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