Answers for "how do you execute the fragment or sqlBatch using scriptdom"

SQL
0

how do you execute the fragment or sqlBatch using scriptdom

using (TextReader reader = new StringReader(script))
{
    TSqlParser parser = new TSql110Parser(true);
    IList<ParseError> errors;
    TSqlFragment fragment = parser.Parse(reader, out errors);
    if (errors != null && errors.Count > 0)
    {
        foreach (ParseError error in errors)
        {
            Console.WriteLine("Line: {0}, Column: {1}: {2}", error.Line, error.Column, error.Message);
            return;
        }
    }

    SqlScriptGenerator sqlScriptGenerator = new Sql110ScriptGenerator();
    TSqlScript sqlScript = fragment as TSqlScript;
    if (sqlScript == null)
    {
        sqlScriptGenerator.GenerateScript(fragment, Console.Out); // TODO execute the script
    }
    else
    {
        foreach (var sqlBatch in sqlScript.Batches)
        {
            Console.WriteLine("-- ");
            sqlScriptGenerator.GenerateScript(sqlBatch, Console.Out); // TODO execute the script
        }
    }
}
Posted by: Guest on May-04-2022

Code answers related to "how do you execute the fragment or sqlBatch using scriptdom"

Code answers related to "SQL"

Browse Popular Code Answers by Language