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:
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">