我写了下面的代码用于运行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);
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?
项目应该添加哪些参考资料?
Microsoft.SqlServer.Server
的引用,如果它现在不存在。并在您的代码中添加一个命名空间即可。 - Dhrumil