KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I create a process in C# to execute sqlcmd /S <servername> /d <dbname> /E /i to run sql script that create tables, views, stored procedures. The problem is the process does not terminate after the execution is completed. I want to know how can I terminate sqlcmd immediately after the operation is completed. Is there any input argument to sqlcmd that I can specify to terminate the process right away or can I do it directly in C#? Update This is the C# code that I use to execute the process. foreach (var file in files) { ////var begin = DateTime.Now; ////context.TrackBuildWarning(string.Format("Start exec sql file at {0}.", DateTime.Now)); Process process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = "sqlcmd.exe"; process.StartInfo.Arguments = string.Format("-S {0} -d {1} -i \"{2}\" -U {3} -P {4}", sqlServerName, databaseName, file, sqlUserName, sqlPassword); process.StartInfo.WorkingDirectory = @"C:\"; process.Start(); process.WaitForExit(); // if I comment out this code it will execute much faster ////context.TrackBuildWarning(string.Format("Finished exec sql file at {0} total time {1} milliseconds.", DateTime.Now, DateTime.Now.Subtract(begin).TotalMilliseconds)); } As you can see, I have comment that if I remove (or comment) out process.WaitForExit() it will execute A LOT faster.
Tags (comma-separated)
Save Edits
Cancel