المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem with BCP in C#



C# Programming
11-12-2009, 03:00 AM
I am working on this application(asp.net 1.1,sql server 2000) that has a huge database , in the frontend there is a provision

to generate a csv file by running a stored procedure which can fetch 50000 records(approx), to acieve this I've used the

following:-
1) running forloop iterating through the dataset and creating a comma separated string, then creating the csv file, but this

process slows down the server immensely when data fetched is huge.
2) DTS packages is failing, because when I am creating a new package and click the defeine column button, the SQL Enterprise

manager just closes itself after a few seconds.
3) BCP command, sometimes works sometimes does not. The code used for running bcp in C# is :-

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "bcp";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.Arguments = @"""exec ETH11.dbo.usp_DownloadInvoiceforDalkia "" queryout ""D:\NewLookLogs\Invoice.csv"" -c -t ,

-T -S";
proc.StartInfo.Arguments = proc.StartInfo.Arguments.Replace("usp_DownloadInvoiceforDalkia ","usp_DownloadInvoiceforDalkia

"+"'"+xSupplierID+"',"+"'"+xBuyerID+"',"+"'"+xFromDate+"',"+"'"+xToDate+"',"+"'"+xType+"',"+""+xCurrentOnly+","+""+xDateType+

","+""+xStatus+","+""+xAllStatus+","+""+xContentType+","+"'invoice.csv',"+"'"+Session.SessionID+"'");
proc.Start();
proc.WaitForExit();