Click here for information on how to use code snippets in VS.NET (2005+)
Literal: ID: strSQLToParseType: System.StringToolTip: The T-SQL you want to parse.Default: "SELECT Ouch Invalid SQL!"Literal: ID: strSQLServerType: System.StringToolTip: The name of the SQL Server you want to parse against.Default: "MYSERVERNAME"Literal: ID: strLoginIDType: System.StringToolTip: The login ID used to connect to the SQL Server you want to parse against.Default: "sa"Literal: ID: strLoginPasswordType: System.StringToolTip: The login password used to connect to the SQL Server you want to parse against.Default: "password"Literal: ID: strDatabaseType: System.StringToolTip: The database you want to parse the T-SQL against.Default: "MyDatabase"Literal: ID: strDatabaseOwnerType: System.StringToolTip: The owner of the database you want to parse the T-SQL against (can be null).Default: "dbo"
ID: strSQLToParseType: System.StringToolTip: The T-SQL you want to parse.Default: "SELECT Ouch Invalid SQL!"
ID: strSQLServerType: System.StringToolTip: The name of the SQL Server you want to parse against.Default: "MYSERVERNAME"
ID: strLoginIDType: System.StringToolTip: The login ID used to connect to the SQL Server you want to parse against.Default: "sa"
ID: strLoginPasswordType: System.StringToolTip: The login password used to connect to the SQL Server you want to parse against.Default: "password"
ID: strDatabaseType: System.StringToolTip: The database you want to parse the T-SQL against.Default: "MyDatabase"
ID: strDatabaseOwnerType: System.StringToolTip: The owner of the database you want to parse the T-SQL against (can be null).Default: "dbo"
// NOTE: This code snippet is designed for VS.NET 2005 or later. // Add a reference to the SQLDMO.DLL file; // usually located in :\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; }
XML View:
Parsing T-SQL Statements with SQLDMO sqldmoparsesql Illustrates how you can parse T-SQL statements against an SQL Server with SQL-DMO. C# .Net Fun - http://www.dotnetfun.com - Michael G. strSQLToParse System.String The T-SQL you want to parse. "SELECT Ouch Invalid SQL!" strSQLServer System.String The name of the SQL Server you want to parse against. "MYSERVERNAME" strLoginID System.String The login ID used to connect to the SQL Server you want to parse against. "sa" strLoginPassword System.String The login password used to connect to the SQL Server you want to parse against. "password" strDatabase System.String The database you want to parse the T-SQL against. "MyDatabase" strDatabaseOwner System.String The 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; } ]>
:\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; } ]>