public void execute(Connection conn)
{
// arguments for sqlcmd.exe utility
var args = String.Format(@" -S {0} -U {1} -P {2} -d {3} -i {4} ", conn.serverName, conn.username, conn.password, dbName, sql);
try
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "sqlcmd";
p.StartInfo.Arguments = args;
p.Start();
// waiting for exit makes this very slow
// but not waiting can cause memory overflow
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
success = true;
}
catch (Exception e)
{
success = false;
exception = e.ToString();
}
finally
{
attempts++;
}
}