Is it possible to access the SQL Server "by-product messages" via ADO.NET? Due to the lack of words, by "by-product messages" I mean the output which appears in the Messages tab in Microsoft SQL Server Management Studio. What I particularly have it mind is to read the output of SET STATISTICS TIME ON. It appears that SqlDataReader does not offer anything in this matter.
Select tab from top menu-bar TOOLS, then Connect to Database… Browse your database file and click the OK button. After connecting to the new database file create an object of OleDBConnection class in case of a database like Oracle or MS-Access and create an object of SqlConnection class in case of MS-SQL database.
In this article, I'll create a console application, use ADO.NET SQL data provider classes to connect to a SQL Server database using C#, and access, update and execute SQL commands using ADO.NET. You can use the same code in your Windows Forms or WPF application.
ADO.NET is the data access component for the . NET Framework. ADO.NET is made of a set of classes that are used for connecting to a database and providing access to relational, XML or application data.
SqlClient (or the newer Microsoft. Data. SqlClient) is the provider or namespace you typically use to connect to an SQL Server.
Yes, there's an event on the SqlConnection
class called SqlInfoMessage
, which you can hook into:
SqlConnection _con = new SqlConnection("server=.;database=Northwind;integrated Security=SSPI;"); _con.InfoMessage += new SqlInfoMessageEventHandler(InfoMessageHandler);
The event handler will look like this:
static void InfoMessageHandler(object sender, SqlInfoMessageEventArgs e) { string myMsg = e.Message; }
The e.Message
is the message printed out to the message window in SQL Server Management Studio.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With