I\'m building a custom db deployment utility, I need to read text files containing sql scripts and execute them against the database.
Pretty easy stuff, so far so g
I ended up writing an implementation of a StringReader to do this.
It handles:
Therefore it will only detect the keyword GO when used as a batch seperator. This means it splits the SQL text correctly.
It also handles if you have appended a sql terminator (semicolon) to the word GO
You can find the code for it here:
You use it like so:
using (var reader = new SqlCommandReader(scriptContents))
{
var commands = new List();
reader.ReadAllCommands(c => commands.Add(c));
// commands now contains each seperated sql batch.
}