G
Guest
Hi
I'd appreciate any help on providing a direction on how to programatically check SQL syntax against scripts collected from a database object (e.g., Table, View, Stored Procedure, Function, Trigger, Alert or Job) or written by a user
I have tried the following but it doesn't work due to the nature of SQL DMO batch processing
SQLDMO.SQLServer objServer = new SQLDMO.SQLServer();
objServer.Connect(ServerName, UserName, Password);
SQLDMO.Database objDatabase=(SQLDMO.Database)objServer.Databases.ItemByID(DBID)
// Script is a parameter containing Script from a View or Stored Procedure or Function or Table ...see belo
/
SET QUOTED_IDENTIFIER OFF
G
SET ANSI_NULLS OFF
G
CREATE VIEW VIEWNAME A
SELEC
SY50.DATE1
SY50.TIME1
SY50.USERID
SY14.USERNAME
SY50.SECDESC
SY50.INQYTYP
FRO
DATABASENAME..SY05000 SY50 (NOLOCK
INNER JOIN SY01400 SY14 (NOLOCK) ON (SY14.USERID = SY50.USERID AND SY14.RELID=0
WHER
DATEDIFF (DAY, DATE1, GETDATE()) <= 14 AN
( INQYTYPE = 2 O
INQYTYPE = 4 O
INQYTYPE = 7 O
INQYTYPE = 8 O
INQYTYPE = 9 O
INQYTYPE = 18 O
INQYTYPE = 19 O
INQYTYPE = 20 OR
INQYTYPE = 15
G
SET QUOTED_IDENTIFIER OFF
G
SET ANSI_NULLS ON
G
*
string strCmd= @"SET PARSEONLY ON\r\nGO\r\n" + Script + @"\r\nSET PARSEONLY OFF\r\nGO\r\n"
SQLDMO.QueryResults qrs=objDatabase.ExecuteWithResultsAndMessages(strCmd, strCmd.Length,out strMsg)
I got the following run-time error
Additional information: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '\'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 4: Incorrect syntax near 'GO'
[Microsoft][ODBC SQL Server Driver][SQL Server]'CREATE VIEW' must be the first statement in a query batch
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 31: Incorrect syntax near 'GO'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 33: Incorrect syntax near 'GO'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 35: Incorrect syntax near 'GO'
Thanks!
I'd appreciate any help on providing a direction on how to programatically check SQL syntax against scripts collected from a database object (e.g., Table, View, Stored Procedure, Function, Trigger, Alert or Job) or written by a user
I have tried the following but it doesn't work due to the nature of SQL DMO batch processing
SQLDMO.SQLServer objServer = new SQLDMO.SQLServer();
objServer.Connect(ServerName, UserName, Password);
SQLDMO.Database objDatabase=(SQLDMO.Database)objServer.Databases.ItemByID(DBID)
// Script is a parameter containing Script from a View or Stored Procedure or Function or Table ...see belo
/
SET QUOTED_IDENTIFIER OFF
G
SET ANSI_NULLS OFF
G
CREATE VIEW VIEWNAME A
SELEC
SY50.DATE1
SY50.TIME1
SY50.USERID
SY14.USERNAME
SY50.SECDESC
SY50.INQYTYP
FRO
DATABASENAME..SY05000 SY50 (NOLOCK
INNER JOIN SY01400 SY14 (NOLOCK) ON (SY14.USERID = SY50.USERID AND SY14.RELID=0
WHER
DATEDIFF (DAY, DATE1, GETDATE()) <= 14 AN
( INQYTYPE = 2 O
INQYTYPE = 4 O
INQYTYPE = 7 O
INQYTYPE = 8 O
INQYTYPE = 9 O
INQYTYPE = 18 O
INQYTYPE = 19 O
INQYTYPE = 20 OR
INQYTYPE = 15
G
SET QUOTED_IDENTIFIER OFF
G
SET ANSI_NULLS ON
G
*
string strCmd= @"SET PARSEONLY ON\r\nGO\r\n" + Script + @"\r\nSET PARSEONLY OFF\r\nGO\r\n"
SQLDMO.QueryResults qrs=objDatabase.ExecuteWithResultsAndMessages(strCmd, strCmd.Length,out strMsg)
I got the following run-time error
Additional information: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '\'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 4: Incorrect syntax near 'GO'
[Microsoft][ODBC SQL Server Driver][SQL Server]'CREATE VIEW' must be the first statement in a query batch
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 31: Incorrect syntax near 'GO'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 33: Incorrect syntax near 'GO'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 35: Incorrect syntax near 'GO'
Thanks!