I'm trying to use the TSql100Parser.ParseStatementList method to programatically parse sql statements and pull out object names. This is from the Microsoft.Data.Schema.ScriptDom.Sql namespace. Here's the code:
string sql = "CREATE VIEW testView AS SELECT * from testTable";
var parser = new TSql100Parser(false);
StatementList parsedStatements; IList errrors;
using (TextReader reader = new StringReader(sql))
{
parsedStatements = parser.ParseStatementList(reader, out errors);
}
The ParseStatementList method returns null, and inserts two errors to the errors list. The errors are "Invalid syntax near CREATE" and "Invalid syntax near VIEW." This is weird because the same sql statement is successfully parsed by the TSql100.Parse method. What's also weird is that the above code successfully parses the SQL "DROP VIEW testView"
Any ideas why it won't parse my view creation sql? Thanks!