Search code examples
c#bcp

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


I am trying to do a bulk copy using BCP via my C# application. This is the command I need to execute:

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]

And I execute the command as follows: System.Diagnostics.Process.Start("bcp.exe", bcpArgs);

This works fine on my local machine, but when deployed to our dev/prod servers, I get a "The system cannot find the file specified" exception. However, if I run the bcpArgs directly in commandline, the process is successful.

What am I missing please?


Solution

  • You have to specify the path of bcp.exe, instead of:

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

    try:

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