I'm trying to open a command prompt through the program and then run bcp. Here is the code.

System.Diagnostics .Process proc = new System.Diagnostics.Process ();
proc.StartInfo.FileName = "bcp";
proc.StartInfo.Arguments = @"select * from dbname" queryout C:\filename.csv -S servername\instance -U sa -P password –N;
proc.Start ();

On the queryout I get an error "; expected"

Any thoughts?

Recommended Answers

All 3 Replies

I'm assuming you mean a compile time error and not a runtime error? That would be because you are not terminating or escaping your string properly. Try this:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
      proc.StartInfo.FileName = "bcp";
      proc.StartInfo.Arguments = @"select * from dbname"" queryout C:\filename.csv -S servername\instance -U sa -P password –N";
      proc.Start();

This code worked :

proc.StartInfo.FileName = "bcp";
proc.StartInfo.Arguments = @"""select * from ims3.dbo.cinfo"" queryout ""C:\filename"" -S server\instance -U sa -P password -N";

I needed to double quote the sub strings.

I'm glad to see you found a solution.

Please mark this thread as solved if your question has been answered

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.