I have a large auditing stored procedure that prints values and runs some SELECT statements. When running within SQL Management Studio we have the use select to display “Results to Text” so all of the SQL results and print statement display in one place.
Now I need to have some C# code also call this auditing procedure at the end of the process and basically store all data that would be in the “Results to Text” window into a .txt file.
How can this be done?
You can get the PRINT output but not in the same way you get the resultsets. If your output assumes a specific sequence of PRINT and resultset data, this isn’t really possible.
You can get the PRINT output via a callback/eventhandler:
…
When you execute something against that SqlConnection, it will call that callback for each line of printed output.