Home » Tutorials » C# » Get Message Info Of SQL Server In C#

Get Message Info Of SQL Server In C#

Fetch Hardware Information Using C#
Convert List to XML in C#

Get Message Info Of SQL Server In C#

Today I am going to explain you how to get message information of SQL Server in C#.You must have a question,Why this would be helpful to us? Most of us, used to create Stored Procedure in Sql Server database to achieve security, execution plans, reusability and decoupling. But sometime we want to capture some of information at time of exceptions like what was last statement ran, what was the final inputs in stored procedure was etc.. To achieve this things we could capture logs by PRINTING statement in SQL Server and can get whole message in your log file to dig into.

Below is the Database of EmployeeDB, in which there is a stored procedure which will print only messages.

 

Lets execute PrintMessagesToCapture SP and whose output will be as shown below:

GetMessageInfoOfSQLServerInCsharp-2-OP

InfoMessage is helpful to capture message from Sql Server

cn.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e)

{ Console.WriteLine(e.Message); };

Below is the code snippet in C#.

OUTPUT:

 

GetMessageInfoOfSQLServerInCsharp

 

About

Hello friends, My self Dhruv Sheth, I have more than 6 years of Industrial experience as a Software Developer. In my career I got chance to work with asp.net, c#,Web API, JavaScript, JQuery, WPF, WCF , Windows Application, PostScript, vb.net, GhostScript etc. So I have decided to share my knowledge with everyone and finally I have come up with TechnoThirsty.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload CAPTCHA.




DISCLAIMER:
The content is copyrighted to technothirsty.com and may not be reproduced on other websites without permission from the owner.You may contact us using the information below.