Grabing PRINT statements via ADO .Net when no exception is raised?

  • Hi there,

    For various reasons, I need to build a small Query Analyser kind of tool in .Net and everything works fine but I'd like to add a little twist to show the PRINT statements executed within my stored procs.

    A bit like in SSMS, I'd have one tab showing the resultset while I'd like to show the potential Debug/Print statements in another tab.

    I know I can fetch all PRINT statements through the Errors collection of a SqlException raised but only errors raised at a certain level generate exceptions... and I don't really want exceptions raised if everything is fine anyway.

    Question: is there a way to collect all print statements and minor errors without going through the SqlException class?

    Many Thanks

    Eric :unsure:

  • yes you can Eric; i did the same thing making a SSMS clone in .NET, for me it was just for fun, but you learn all the pieces you need.

    What you are looking for is SQLConnection.InfoMessage

    all the print statements, as well as stuf like rows affected and stuff appear there.

    googling for ".net sql print statements InfoMessage event in SqlConnection" gets you other code examples as well.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Brilliant!

    Many thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply