I want to execute all sql files in folders. I found the answer in this question is helpful. I can use their command and it works as expect.
I want to run it from C# code. i tried a couple ways but I couldn't get the result. Below is the code that I have tried but not success.
Process process = new Process();
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = string.Format("for %f in ({2}/*.sql) do sqlcmd /S {0} /d {1} /U {3} /P {4} /E /i {5}",
sqlServerName, databaseName, folder, sqlUserName, sqlPassword, @"""%f""");
process.StartInfo.WorkingDirectory = @"C:\";
process.Start();
process.WaitForExit();
I want to know how can I move this DOS command for %f in (*.sql) do sqlcmd /S <servername> /d <dbname> /E /i "%f"
into C# code