I use sqlcmd to run large script SQL from C# code:
ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S . -i "+ currentDBScript.Value + " -b");
info.UseShellExecute = false;
//No new window is required
info.CreateNoWindow = true;
//The windows style will be hidden
info.WindowStyle = ProcessWindowStyle.Hidden;
//The output will be read by the starndar output process
info.RedirectStandardOutput = true;
Process proc = new Process();
proc.StartInfo = info;
//Start the process
proc.Start();
Note that currentDBScript.Value
is the path of my file script
I want to catch error if script executed by sqlcmd didn't succeed.