SQL Server 2008
我敢说,使用所有正确的参考资料:
System.Data.SqlClient;
Microsoft.SqlServer.Management.Smo;
Microsoft.SqlServer.Management.Common;
Microsoft.SqlServer.Management.Sdk.Sfc;
所有编译都没有错误。
为了便于调试,我已将代码精简到几乎为零。
连接服务器正常等等。
执行以下代码:
SqlConnection connection = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(connection));
server.ConnectionContext.ExecuteNonQuery(sqlDBQuery);
sqlDBQuery
字符串在哪里:USE [master] GO ALTER DATABASE [Cassiopeia] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [Cassiopeia] SET ANSI_NULLS OFF GO
但是“sqlDBQuery”是什么并不重要,我总是得到同样的错误,比如
GO附近的语法不正确
.
我相信 SMO 会处理这个问题,当我看到我ConnectionContext
的时候说 BatchSeparator = "GO"
如果我删除 GO,那就可以了……可以这么说,但我真的需要知道为什么我的 SMO 不起作用。
我到处都看到它只是说“像这样使用smo,你就没事了”。嗯……不适合我。
请参阅 Jon Galloway 的这篇文章以供参考: http : //weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-2D00-the-easy-way.aspx
问候