Using SMO, still no ... ConnectionContext.ExecuteNonQuery (script) can't understand "GO"
SQL Server 2008
Using all the correct links, I dare say:
System.Data.SqlClient;
Microsoft.SqlServer.Management.Smo;
Microsoft.SqlServer.Management.Common;
Microsoft.SqlServer.Management.Sdk.Sfc;
All compilations are error free.
I lost my code to zero to make it easier to debug.
Server connection, etc.
Extracting the following code:
SqlConnection connection = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(connection));
server.ConnectionContext.ExecuteNonQuery(sqlDBQuery);
Where sqlDBQuery
is the string:USE [master] GO ALTER DATABASE [Cassiopeia] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [Cassiopeia] SET ANSI_NULLS OFF GO
But it doesn't matter what "sqlDBQuery" is, I always get the same error as
incorrect syntax next to GO
...
I was sure SMO would take care of this when I look at mine ConnectionContext
says BatchSeparator = "GO"
If I uninstall GO, it goes ... so to speak, but I really need to know why my SMO isn't working.
Wherever I look, it just says, "Use smo like this and you're fine." Well ... doesn't work for me.
See this post from Jon Galloway for reference: http://weblogs.asp.net/jgalloway/archive/2006/11/07/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-2D00- substitute simple way.aspx
Hello
source to share
"GO" is not a SQL language
This is a packet separator used by client tools like SSMS (which does not send "GO" to the database engine)
SMO does not parse the script into packages like SSMS, so the database engine throws an error.
After comment:
"GO" should be on a separate line by itself
This is your script literally this (copy / paste 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 is it formatted correctly?
USE [master]
GO
ALTER DATABASE [Cassiopeia] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [Cassiopeia] SET ANSI_NULLS OFF
GO
source to share