I'm write this code for run sql server script:
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);
but this line :
Microsoft.SqlServer.Server server = new Microsoft.SqlServer.Server(new ServerConnection(conn));
i get this error:
Are you missing reference?
what reference should be add to the project?
using System.Data.SqlClient;on namespace section..Microsoft.SqlServer.Serverin your project, if its not present now. And add a namespace for it in your code this should do it