从SQL Job

问题描述

我有一个正在数据库服务器上运行的sql作业,它在调用应用程序服务器以运行exe“ cmd Exec步骤类型”的步骤之一上运行

exe应用程序“ C#”被正确调用并完成所有预期的任务,最后一步,它运行cmd.exe来合并几个文件

**手动运行exe应用程序时,它可以按预期运行,但是通过sql Job调用时,它返回以下错误

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()

值得一提的是,一切都在E:\驱动器上运行

这是我的代码

    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);

解决方法

尝试删除指定工作目录的行吗?

,

我发现了问题,这与UNC路径有关。 该命令试图使用文件的UNC路径合并DB Server上的文件,而cmd.exe不支持UNC,因此该命令在不存在该目录的DB Server上运行。

我切换为使用C#应用程序本身在应用程序服务器上合并文件。