coding @ the speed of thought RSS 2.0
 Thursday, August 14, 2008
As i was just about to code a logging system for a project, i remembered a couple of fine methods which SqlConnection class has.
RetrieveStatistics();

It works with first enabling the stats mode, resetting the stats and when the command is executed, finally retrive the stats.
string strConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=FooDB;Integrated Security=True";
 using (SqlConnection conSQL = new SqlConnection(strConnectionString))
 {
     using (SqlCommand cmdSQL = new SqlCommand("select * from Foo", conSQL))
     {
         cmdSQL.CommandType = CommandType.Text;
         try
         {
             conSQL.Open();
             conSQL.StatisticsEnabled = true;
             
             conSQL.ResetStatistics();
             SqlDataReader drdActiveConfiguration = cmdSQL.ExecuteReader();
             IDictionary idcStat= conSQL.RetrieveStatistics();

             foreach (DictionaryEntry dceItem in idcStat)
             {
                 Console.WriteLine("Key: {0}, Value: {1}", dceItem.Key.ToString(), dceItem.Value.ToString());
             }

             DataSet dsActiveConfiguration = new DataSet();
             dsActiveConfiguration.Load(drdActiveConfiguration, LoadOption.OverwriteChanges, new string[] { "Foo1" });

             dsActiveConfiguration.Clear();
             conSQL.Close();
         }
         catch (Exception excp)
         {
         }
     }
 }
By using this method, you get a quite information about the execution process...

Key: NetworkServerTime, Value: 375
Key: BytesReceived, Value: 224
Key: UnpreparedExecs, Value: 1
Key: SumResultSets, Value: 0
Key: SelectCount, Value: 0
Key: PreparedExecs, Value: 0
Key: ConnectionTime, Value: 390
Key: ExecutionTime, Value: 390
Key: Prepares, Value: 0
Key: BuffersSent, Value: 1
Key: SelectRows, Value: 0
Key: ServerRoundtrips, Value: 1
Key: CursorOpens, Value: 0
Key: Transactions, Value: 0
Key: BytesSent, Value: 388
Key: BuffersReceived, Value: 1
Key: IduRows, Value: 0
Key: IduCount, Value: 0
Press any key to continue . . .


which is very handy :)

Thursday, August 14, 2008 8:39:59 PM (GTB Standard Time, UTC+02:00)  #    Comments [0] -
Software
Archive
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2009
Levent YILDIZ
Sign In
Statistics
Total Posts: 103
This Year: 1
This Month: 1
This Week: 0
Comments: 30
Themes
Pick a theme:
All Content © 2009, Levent YILDIZ
DasBlog theme 'Business' created by Christoph De Baene (delarou)