How to get the statistics about the Database usage using sqlConnection object

Hi

One of the most important things needed to track and improve Application performance is Statistics. Statistics related to database work is of great importance to the developers. Since they need to track how many times the application is calling the database and how much time each query is taking and which query can be improved to increase the performance of the Application. We can use the sqlConnection object to retrieve the statistics related to database work.

The sqlConnection object gives us "RetrieveStatistics()" method that can give us some useful information. But to get the statistics you need to tell the SQL Connection object that you want to keep track of the connection related statistics. You can do that using sqlconnection.StatisticsEnabled() method

(Note- This method is not available in the oledbconnection object or oracleconnection object).

 Now you need to open the connection and execute the query or procedure. And then close the connection.

To retrieve the statistics from the connection use the following code

IDictionary constats = myConnection.RetrieveStatistics();

String strConnectionStatistics = "";

foreach (DictionaryEntry entry in constats)

{

strConnectionStatistics  += Key is " + entry.Key.ToString() + "Value:" + entry.Value.ToString());

strConnectionStatistics  += "\n";

}

These statistics can be very helpful in looking which query is taking what time and what can be done to increase the performance

Hope this helps
Thanks
Vikram

P.S.- This method is available only in ASP.NET 2.0


Share this post   Email it

Feedback

Posted on 11/2/2009 2:36:59 PM

Isnt it avialable in Asp 3.0/3.5?

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2010 Vikram Lakhotia