title: executing a sql script from C# results in an error
body: <p>I have this class that I am trying to execute my script from:</p>
  
  <pre><code>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;
        }
      }
    }
  }
  </code></pre>
  
  <p>It is executing a sql script, created by SSMS, that I have in the project set to copy every time.</p>
  
  <p>I am getting this message:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I checked every one of my projects and they are using .Net Framework 4. I get this message on this line:</p>
  
  <pre><code>server.ConnectionContext.ExecuteNonQuery(script);
  </code></pre>
  
  <p>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. </p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT#1</strong></p>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>EDIT#2</strong></p>
  
  <p>I believe it is the <code>Microsoft.SqlServer.ConnectionInfo</code> since it's version is v2.0.50727, which matches the above version. </p>
  
  <p><strong>EDIT#3</strong></p>
  
  <p>Ok, I'm confused on this. I would have thought, when I added <code>Microsoft.SqlServer.ConnectionInfo</code> that I was adding the .Net 4.0 version as shown from the picture below:</p>
  
  <p><img src="https://i.stack.imgur.com/SVdvQ.png" alt="enter image description here"></p>
  
  <p>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?</p>
  
  <p>Isn't this just a work around instead of a real fix for the issue:</p>
  
  <pre><code>&lt;startup useLegacyV2RuntimeActivationPolicy="true"&gt;
  </code></pre>