使用SMO,仍然没有去... ConnectionContext.ExecuteNonQuery(脚本)无法理解" GO" [英] Using SMO, still no go... ConnectionContext.ExecuteNonQuery(script) can't understand "GO"
问题描述
SQL Server 2008的
SQL Server 2008
使用所有我敢说正确的引用:
Using all the correct references I dare say:
System.Data.SqlClient;
Microsoft.SqlServer.Management.Smo;
Microsoft.SqlServer.Management.Common;
Microsoft.SqlServer.Management.Sdk.Sfc;
所有编译没有任何错误。
All compiles with no errors.
我已经剥夺code下降到几乎为零,方便调试。
I have stripped code down to almost zero for easy debugging.
连接到服务器好吗等等。
Connecting to server alright and so on.
Excuting以下code:
Excuting following code:
SqlConnection connection = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(connection));
server.ConnectionContext.ExecuteNonQuery(sqlDBQuery);
其中, sqlDBQuery
是一个字符串:使用[大师] GO ALTER DATABASE [仙后座] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [仙后座] SET ANSI_NULLS OFF GO
但它并不重要sqlDBQuery是,我总是得到同样的错误,像
But it doesn't matter what "sqlDBQuery" is, I always get the same error, like
GO附近的语法不正确
incorrect syntax near GO
我是相信SMO会照顾这,当我看着我的 ConnectionContext
是说BatchSeparator =GO
I was in belief that SMO would take care of this, when I look at my ConnectionContext
is says BatchSeparator = "GO"
如果我删除GO这是一个去......可以这么说,但我真的需要知道为什么我的SMO是行不通的。
If I remove GO it's a go... so to speak but I really need to know why my SMO doesn't work.
我到处看看它只是说使用SMO这样和你过精。嗯......不为我工作。
Everywhere I look it just says "use smo like this and you're off fine". Well... doesn't work for me.
请参阅这篇文章由乔恩·加洛韦,以供参考: <一href="http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-_2D00_-the-easy-way.aspx" rel="nofollow">http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-2D00-the-easy-way.aspx
See this post by Jon Galloway for reference: http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-2D00-the-easy-way.aspx
问候
推荐答案
GO是不是SQL语言
这是用于象SSMS客户端工具(不发送GO数据库引擎)批次分离
It's a batch separator used by client tools like SSMS (which does not send "GO" to the database engine)
SMO不分析脚本到像SSMS会做的批次,所以数据库引擎将引发错误。
SMO does not parse the script into batches like SSMS would do, so the database engine throws an error.
意见后:
GO一定要由自己单独的行
"GO" must be on a separate line by itself
从字面上是你的脚本这个(复制/粘贴从我编辑的问题)
Is your script literally this (copy/paste from when I "edit" the question)
USE [master] GO ALTER DATABASE [Cassiopeia] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [Cassiopeia] SET ANSI_NULLS OFF GO
或此格式正确无误?
or this correctly formatted?
USE [master]
GO
ALTER DATABASE [Cassiopeia] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [Cassiopeia] SET ANSI_NULLS OFF
GO
这篇关于使用SMO,仍然没有去... ConnectionContext.ExecuteNonQuery(脚本)无法理解&QUOT; GO&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!