تسجيل الدخول

مشاهدة النسخة كاملة : Help : bcp.exe blocked !!!!



C# Programming
09-09-2009, 05:40 PM
Hi,

i want to use 'bcp.exe' to extract data from a SQL Server database to my local drive.
The method to call 'bcp.exe' is:


Command = " bcp.exe \"" + selectStatement + "\" queryout " + fileName + " -T -c -t, -r \\n ";


public void ExecuteCommandSync(object command)
{
try
{
ProcessStartInfo pInfo = new ProcessStartInfo("cmd", "/c " + command);
pInfo.RedirectStandardOutput = true;
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = pInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
Console.WriteLine(result);
}
catch(Exception ex)
{
}
}



when this function is called, the program sometimes blocked at 'proc.StandardOutput.ReadToEnd()'
but didn't raise any Exceptions.
when i run the same command on my win command shell, it runs perfectly.
what is wrong in my code?
how can i fix this? i need to execute more than one bcp export call in my application.

Thanks in advance.