When using SqlCommand to execute a non-query (such as a database restore), is it possible to programatically get the text that would normally be posted to the ‘Messages’ tab if using the Management Studio? And if so how?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, there’s an event hook on the SqlCommand object called SqlInfoMessage, which you can hook into:
The event handler will look like this:
The ‘e.Message’ is the message printed out to the message window in SQL Server Mgmt Studio.
Marc