Hi. I am trying to use the BCP tool in a process ( .NET console application)
There are times, when the data is getting passed, there are times the BCP is not passing any data. How to find if there is any error while the BCP is executing. I have tried the below code, but not been able to capture any error.
using (var process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = "BCP";
process.StartInfo.Arguments = "\"" + Query + " \" queryout " + "\"" + fileName.Trim() + "\"" + " -T -S " + servername + " -d " + dbinstance + " -b 1000 -c -C 65001 -t~";
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
string stderr = process.StandardError.ReadToEnd();
console.writeline(stderr);
}
How to capture the error ? Is the above method correct ? Thanks