using BCP utility in C# RRS feed

  • Question

  • User-73514677 posted


    I have a C# applicaitotn, in which I want to use the SQL BCP utility. I have been able to run a single command and the data is extracted, but I want to make it as a function, which can be run for multiple queries.

    All the SQL statements are in resx file. I am able to iterate through the data in resx file, but not sure how to pass it to the BCP process?

    I have my current code as below:

                    String.Format("\"select 'COUNTRY', 'MONTH' union all SELECT COUNTRY, cast(MONTH as varchar(2)) FROM DBName.dbo.TableName\" queryout {0}FILE_NAME.csv -c -t; -T -{1}", ExportDirectory, SQLServer));
     static void processCMD(string fileName, string arguments)
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = fileName;
                proc.StartInfo.Arguments = arguments;

    Is the above the right way to use BCP?

    Each query should save in different file.


    Thursday, December 3, 2020 12:44 PM