To parse the SQL Server script using C#, the following DLL's have to be referenced in the project.
Microsoft.Data.Schema.ScriptDom.dll
Microsoft.Data.Schema.ScriptDom.Sql.dll
Once you have Visual Studio 2010 installed in your machine, the above DLL's would be available at C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\
Once the above DLL's are referenced in the project, the below namespaces have to be included:
using Microsoft.Data.Schema.ScriptDom.Sql;
using Microsoft.Data.Schema.ScriptDom;
Microsoft.Data.Schema.ScriptDom.dll
Microsoft.Data.Schema.ScriptDom.Sql.dll
Once you have Visual Studio 2010 installed in your machine, the above DLL's would be available at C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\
Once the above DLL's are referenced in the project, the below namespaces have to be included:
using Microsoft.Data.Schema.ScriptDom.Sql;
using Microsoft.Data.Schema.ScriptDom;
TSql100Parser class available in Microsoft.Data.Schema.ScriptDom.Sql namespace can be used to parse the SQL scripts written for SQL Server 2008. Similarly, TSql90Parser class is available targeting the scripts written for SQL Server 2005. A separate class TSqlAzureParser is also available in the same namespace targetting SQL Azure.
TSql100Parser has the .Parse method which takes TextReader as input and returns IList<ParseError> in the out parameter. If the returning list contains any record, that mean the parsing has failed and the script has some errors.
Below is the code snippet for the parsing the SQL script:
Below is the code snippet for the parsing the SQL script:
No comments:
Post a Comment