0

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?

2
Contributors
3
Replies
7
Views
8 Years
Discussion Span
Last Post by sknake
0

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();
0

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.

0

I'm glad to see you found a solution.

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.