我寫這篇文章的代碼運行在C#中的SQL服務器腳本:
爲什麼我在c#中運行sql server腳本時出錯?
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!!!");
但是當我運行的應用程序,我得到這個錯誤:
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
逐一檢查您的項目屬性,並確保每一個項目中使用.NET框架的版本相同。 (或者按照重複的鏈接掃描地毯下) – Steve