使用 BCP 时如何修复 "System cannot find the file specified" 异常

How to fix the "System cannot find the file specified" exception when using BCP

我正在尝试通过我的 C# 应用程序使用 BCP 进行批量复制。这是我需要执行的命令:

var bcpArgs = "EXEC spReportExecutor @Query = 'SELECT * FROM ExpAifaBrosureCommTape', @Parameters = '<Parameters> <DBToUse>sql_converted_absaDR</DBToUse></Parameters>'" queryout "C:\MISAutomationReports\BCP\AifaBrosureCommissionTape.dat" -e"C:\MISAutomationReports\BCP\AifaBrosureCommissionError.txt" -T -c -S [myserver] -d [mydatabase]

然后我执行命令如下: System.Diagnostics.Process.Start("bcp.exe", bcpArgs);

这在我的本地机器上工作正常,但是当部署到我们的 dev/prod 服务器时,我得到一个 "The system cannot find the file specified" 异常。但是,如果我直接在命令行中运行 bcpArgs,过程是成功的。

请问我错过了什么?

您必须指定 bcp.exe 的路径,而不是:

System.Diagnostics.Process.Start("bcp.exe", bcpArgs)

尝试:

System.Diagnostics.Process.Start("path\bcp.exe", bcpArgs)