I have a SQL Job that's running on a DB Server and on one of the steps it calls an application server to run an exe "cmd Exec step type"
the exe application "C#" is invoked properly and does all its intended tasks, as a final step it runs cmd.exe to merge couple of files.
** When running the exe application manually, it's working as intended, but when invoking through SQL Job it's returning the below error:
Error in MergeFiles() Method : System.ComponentModel.Win32Exception (0x80004005): The directory name is invalid
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at _700CreditBillingScheduler.Billing700C.MergeFilesInPath()
Worth saying everything is running on E:\ drive
Here is my code:
string filePath = "E:\\HomeFolder\\ApplicationFolder"; // where merged file will be created
string sourcePath = "E:\\HomeFolder\\ApplicationFolder\\Transaction.Indiv.Files\\*.csv"; // to be merged
string commandLine = String.Format("/c copy /b {0} {1}", sourcePath, "mergedFileName");
var cmd = new ProcessStartInfo("cmd.exe", commandLine);
cmd.WorkingDirectory = filePath;
cmd.UseShellExecute = false;
Process.Start(cmd);
Try to remove the line where you specify the working dir ?
I found the issue, it has to do with the UNC path. The command was trying to merge the files on DB Server using the UNC path of the file, and UNC isn't supported through cmd.exe, so instead it ran on DB Server where the directory doesn't exist.
I switched to merge the files on application server using the C# application itself.
User contributions licensed under CC BY-SA 3.0