Parsing T-SQL Statements with SQLDMOsqldmoparsesqlIllustrates how you can parse T-SQL statements against an SQL Server with SQL-DMO.C# .Net Fun - http://www.dotnetfun.com - Michael G.strSQLToParseSystem.StringThe T-SQL you want to parse."SELECT Ouch Invalid SQL!"strSQLServerSystem.StringThe name of the SQL Server you want to parse against."MYSERVERNAME"strLoginIDSystem.StringThe login ID used to connect to the SQL Server you want to parse against."sa"strLoginPasswordSystem.StringThe login password used to connect to the SQL Server you want to parse against."password"strDatabaseSystem.StringThe database you want to parse the T-SQL against."MyDatabase"strDatabaseOwnerSystem.StringThe owner of the database you want to parse the T-SQL against (can be null)."dbo"
:\Program Files\Microsoft SQL Server\\Tools\Binn
SQLDMO.SQLServerClass sqlServer = new SQLDMO.SQLServerClass();
try
{
String strSQLToParse = $strSQLToParse$;
sqlServer.Connect($strSQLServer$, $strLoginID$, $strLoginPassword$);
SQLDMO._Database db =
sqlServer.Databases.Item($strDatabase$, $strDatabaseOwner$);
try
{
db.ExecuteImmediate(strSQLToParse, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_ParseOnly, null);
}
catch (Exception e)
{
// Parse error...
}
}
catch (Exception err)
{
// SQL-DMO Error...
}
finally
{
sqlServer.Close();
sqlServer = null;
}
]]>