我寫的運行SQL服務器腳本驗證碼:
我怎樣才能用c#運行sql服務器腳本?
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);
Microsoft.SqlServer.Server server = new Microsoft.SqlServer.Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
但此行:
Microsoft.SqlServer.Server server = new Microsoft.SqlServer.Server(new ServerConnection(conn));
我得到這個錯誤:
Are you missing reference?
應該加什麼參考該項目?
使用'使用System.Data.SqlClient的;'名稱空間部分.. –
看到這個https://開頭msdn.microsoft.com/en-us/library/system.data.sqlclient%28v=vs.110%29.aspx –
我使用System.Data.SqlClient添加;但如此起牀錯誤! –