Private void RunScripts() { // Start SQLCMD process. ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "SQLCMD.EXE"; string args = "-S " + this.Server; if (string.IsNullOrEmpty(this.UserName)) args += " -E"; else args += " -U " + this.UserName; if (!string.IsNullOrEmpty(scriptFile.Database)) args += " -d " + scriptFile.Database; if (string.IsNullOrEmpty(this.Password)) args += " -i " + scriptFilePath; else args += " -P " + this.Password + " -i " + scriptFilePath; psi.Arguments = args; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.UseShellExecute = false; using (Process executorProcess = Process.Start(psi)) { executorProcess.EnableRaisingEvents = true; executorProcess.OutputDataReceived += new DataReceivedEventHandler( this.executorProcess_DataReceived); executorProcess.ErrorDataReceived += new DataReceivedEventHandler(executorProcess_ErrorDataReceived); executorProcess.BeginOutputReadLine(); executorProcess.BeginErrorReadLine(); bool exited = false; while (!exited) { exited = executorProcess.WaitForExit(60000); if (!exited && this.StopSignal) { try { executorProcess.Kill(); } catch { } } } try { executorProcess.CancelOutputRead(); executorProcess.CancelErrorRead(); } catch { } } void executorProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e) { Console.WriteLine(e.Data); } private void executorProcess_DataReceived(object sender, DataReceivedEventArgs e) { Console.WriteLine(e.Data); }
System.Information.EventLog
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)