BCP process request timeout

Padmanabhan, Venkatesh 246 Reputation points
2021-01-06T09:08:34.637+00:00

Hi.
I am using BCP command in a .NET console application.

The query returns around 6,00,000 rows and takes 5 mins 43 seconds when running the query in SSMS.

My bcp command looks like this:
BCP "SELECT columns FROM tablename where condition " queryout "Pathand FileName" -T -S ServerName -d DatabaseName -b 500 -c -C 65001 -t~

The overall code is:

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 500 -c -C 65001 -t~";

                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();
                string stderr = process.StandardError.ReadToEnd();

            }

How to fix this timeout issue ? Thanks

SQL Server | Other
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.