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 found the code below while searching for an answer to this issue:
http://blogs.msdn.com/b/onoj/archive/2008/02/26/incorrect-syntax-near-go-sqlcommand-executenonquery.aspx
Pros: It's short and simple to understand and worked perfectly for my needs.
Cons: It is less efficient than Stream based solutions and is case sensitive (i.e "GO" not "go").
string[] commands = sql.Split(new string[]{"GO\r\n", "GO ", "GO\t"}, StringSplitOptions.RemoveEmptyEntries );
foreach (string c in commands)
{
var command = new SqlCommand(c, masterConnection);
command.ExecuteNonQuery();
}