If you are only trying to validate the syntax (and not the existence of the database objects), you may take a look at the TSqlParser Class.
You will need to add the following references to your project:
- Microsoft.Data.Schema.ScriptDom
- Microsoft.Data.Schema.ScriptDom.Sql
A simple way to do that is to edit your .csproj file and add the following two entries along with the existing ones and reload the project:
<ItemGroup>
<Reference Include="Microsoft.Data.Schema.ScriptDom.Sql" />
<Reference Include="Microsoft.Data.Schema.ScriptDom" />
<!-- other Reference tags -->
</ItemGroup>
Some sample usage:
private void btnParse_Click(object sender, EventArgs e)
{
var parser = new TSql100Parser(true);
IList<ParseError> errors;
var result = parser.Parse(new StringReader(richTextBox1.Text), out errors);
// TODO: check the errors
}