0

I have several stored procedures that I need to direct where the output log location should be. You can set that in SQL Agent but how do you set this when calling the stored procedure via C#? C# is .NET 3.5 and SQL Server is 2005.

user31673
  • 13,245
  • 12
  • 58
  • 96

2 Answers2

2

I'm not sure what you mean by output log location - SQL Agent has its own mechanism for running jobs and capturing the output so if you're just running loose stored procedures in C# then anything SQL agent does won't help you.

You need to capture any output in your calling code and handle / log it yourself.

Does Capturing the output of a stored procedure sound like what you're looking for?

Community
  • 1
  • 1
MarcE
  • 3,586
  • 1
  • 23
  • 27
  • The SQL Agent has a log output location you can set in each Step's Advanced area. That captures all output generated by the stored procedure which includes PRINT and select results. I need to get the same output when calling it in c# – user31673 May 14 '12 at 17:51
  • That's what I thought you meant. Afaik you have to handle / log it all yourself - the link I provided was to another SO question that talks about capturing the PRINT output. For select results, they come back in the usual way as result sets or output variables, depending on the way the stored proc is set up. – MarcE May 15 '12 at 00:03
2

I typically create a new table for my log results. You can write to the log table directly from your stored procedure, our create a separate procedure that you call.

I typically use log4Net, since I log from both executable programs and stored procedures. http://logging.apache.org/log4net. Google "log4net logging from stored procedure" for examples.

cdev
  • 166
  • 5