0

I have this class that I am trying to execute my script from:

using System;
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using SSS.ServicesConfig.MiscClasses;

namespace SSS.ServicesConfig.sqlchanges
{
  internal static class ExecuteScript
  {
    public static Status Execute(SqlConnection con, string scripttoexecute)
    {
      var status = new Status();
      try
      {
        var file = new FileInfo(scripttoexecute);
        var script = file.OpenText().ReadToEnd();
        var server = new Server(new ServerConnection(con));
        server.ConnectionContext.ExecuteNonQuery(script);
        file.OpenText().Close();
        status.IsSuccess = true;
        status.Message = "Success!";
        return status;
      }
      catch (Exception ex)
      {
        status.Message = ex.Message;
        status.IsSuccess = false;
        return status;
      }
    }
  }
}

It is executing a sql script, created by SSMS, that I have in the project set to copy every time.

I am getting this message:

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

I checked every one of my projects and they are using .Net Framework 4. I get this message on this line:

server.ConnectionContext.ExecuteNonQuery(script);

Is it saying my .sql file isn't a .Net 4.0 file? I'm not sure I understand what this is referring too that is running 2.0.

Any ideas?

EDIT#1

This is the beginning of my .sql file if that helps. I can post the whole thing but it's real basic, just create a handful of tables:

USE [master]
GO
/****** Object:  Database [SuburbanPps]    Script Date: 4/7/2014 2:00:12 PM ******/
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'SuburbanPps')
BEGIN
CREATE DATABASE [SuburbanPps] ON  PRIMARY 
( NAME = N'SuburbanPps', SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'SuburbanPps_log', SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
END

GO
ALTER DATABASE [SuburbanPps] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [SuburbanPps].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [SuburbanPps] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [SuburbanPps] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [SuburbanPps] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [SuburbanPps] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [SuburbanPps] SET ARITHABORT OFF 
GO

EDIT#2

I believe it is the Microsoft.SqlServer.ConnectionInfo since it's version is v2.0.50727, which matches the above version.

EDIT#3

Ok, I'm confused on this. I would have thought, when I added Microsoft.SqlServer.ConnectionInfo that I was adding the .Net 4.0 version as shown from the picture below:

enter image description here

Is that not correct? I'd rather not have to require two different frameworks when installing my application if I do not need to. Or... am I really confused on what is going on?

Isn't this just a work around instead of a real fix for the issue:

<startup useLegacyV2RuntimeActivationPolicy="true">
12
  • It doesn't seem related to your sql script at all. Commented Apr 7, 2014 at 19:43
  • I wouldn't think it would... I just don't understand what it is referring to. Commented Apr 7, 2014 at 19:44
  • This looks like one of your components is not running the same framework as the rest, perhaps your sql server driver is not up to date. Commented Apr 7, 2014 at 19:45
  • Have you tried this out: stackoverflow.com/questions/2455654/… Commented Apr 7, 2014 at 19:46
  • Likely you have multiple projects in your solution and they're targetting different .NET runtime versions. That, or you are referring to a compiled assembly that is. Commented Apr 7, 2014 at 19:46

1 Answer 1

2

Mixed Mode Assembly? Is this an ASP.Net application?

If so this has been answered and resolved several times. A small change to the Web.config should work.

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

Ref

Sign up to request clarification or add additional context in comments.

4 Comments

I've edited my post and added Edit#3 in response to this. It's a winforms application.
I've had this problem with console apps in the past, and this is the same fixed I made there.
This is good to know, most of my work is in the proverbial "cloud" so its all ASP on the .NET side of the house. The overall solution would be to bring all referenced libraries up to v4.0. Microsoft.SqlServer.ConnectionInfo you may want to copy this resource local to the project if you are having issues with it recognizing the 4.0 version as opposed to the 2.0 version. I have had wonky issues in the past with Visual Studio handling the different versions of the same resource.
The overall solution would be to bring all referenced libraries up to v4.0. That's exactly what I am trying to find out. I will try to copy it the project and see how that works out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.