0

Heyo folks, Just looked on Google and around on this site, and there's very little information. Given a query which is "SELECT * FROM Table WHERE (various)", I'm putting in a BCP utility query like thus, called from C# (.net 3.5, but can be raised).

xp_cmdshell 'bcp "SELECT * FROM [DB].dbo.[table]  " queryout "\\networkpath\bla\file.csv" -N -S localhost -T -E -m0'

However, when I run this query in SQL Management Studio, it helpfully keeps supplying me with "1000 rows were copied." messages. I want to get those messages in my C# application.

I've tried several C# methods, including SqlDependency, SqlConnection.InfoMessage, BeginExecuteNonQuery(), etc; hence the lack of C# code.

What would be the best method to do this?

Cheers

Whoop5
  • 47
  • 2
  • 12

2 Answers2

0

BCP is a command line application being executed on the server via xp_cmdshell; so the bcp is writing to stdout on the server, capturing that output is discussed here Get Results from XP_CMDSHELL ; this might give you what you are looking for.

Community
  • 1
  • 1
PhillipH
  • 6,182
  • 1
  • 15
  • 25
0

I understand the question that way that you want to run this bcp.exe command and monitor its progress. Run it using Process.Start and redirect console output to your application. Then, you can parse it.

If you run it using xp_cmdshell the InfoMessage event will receive the messages (or they might be output as rows, now sure right now).

usr
  • 168,620
  • 35
  • 240
  • 369