1

I'm write this code for run the sql server script on the c#:

string sqlConnectionString = "Data Source=.;Initial Catalog=behzad;Integrated Security=True";
            //string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True";
            FileInfo file = new FileInfo("d:\\behzadBULK.sql");
            string script = file.OpenText().ReadToEnd();
            SqlConnection conn = new SqlConnection(sqlConnectionString);
            Server server = new Server(new ServerConnection(conn));
            server.ConnectionContext.ExecuteNonQuery(script);
            MessageBox.Show("Insert!!!");


but when i run the application i get this error:

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.":null
behzad razzaqi
  • 1,503
  • 2
  • 18
  • 33
  • Check your project properties one by one and be sure that every project use the same version of the NET Framework. (Or follow the duplicate link and sweep it under the carpet) – Steve May 23 '15 at 07:40

2 Answers2

0

try this:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <requiredRuntime version="v4.0.20506" />
</startup>
Amnon Shochot
  • 8,998
  • 4
  • 24
  • 30
Amit Kumar Ghosh
  • 3,618
  • 1
  • 20
  • 24
0

To use CLR 2.0 Mixed mode assemblies Edit your App.Config and add this lines:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
Iman Nemati
  • 427
  • 3
  • 11