GO statements blowing up sql execution in .NET

前端 未结 11 1047
南笙
南笙 2020-12-05 09:48

I have a very simple C# command shell app that executes a sql script generated by SQL Server for scripting schema and data. It\'s blowing up on the \"GO\" statements. Error

11条回答
  •  时光说笑
    2020-12-05 10:28

    If you want to be able to use GO you will need to reference to the following dlls

    Microsoft.SqlServer.ConnectionInfo.dll
    Microsoft.SqlServer.Management.Sdk.Sfc.dll
    Microsoft.SqlServer.Smo.dll Microsoft.SqlServer.SqlEnum.dll

    Then execute like so

     using (SqlConnection conn = new SqlConnection(connection))
     {
         Server db = new Server(new ServerConnection(conn));
         string script = File.ReadAllText(scriptPath);
         db.ConnectionContext.ExecuteNonQuery(script);      
     }
    

提交回复
热议问题