Monday, January 25, 2010

An open source sql profiler

Found a SQL profiler today which is open source.

Hope this will help you to manage low cost projects efficiently :-)

Wednesday, January 20, 2010

My First Look at EnterpriseLibrary.Logging

Last week I got opportunity to work with the logging module of our application.It was done by one of my colleague and he told that it is done using Logging module of .Net EnterpriseLibrary.
After looking around the code, I was surprised on the lines of code below which does the logging.Rest is all taken care by configuration entries in web.config.

using (new Tracer("My Tracer"))
LogEntry le = new LogEntry() { Message = message };

When I looked into the web.config I was able to see some entries in a section named loggingConfiguration

<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

The above code should be inside configSectionsTag.The rest is a new section as follows added after the config sections.

<loggingConfiguration name="Logging Application Block" tracingEnabled="false"
defaultCategory="" logWarningsWhenNoCategoriesMatch="true">
<add fileName="log.log"
header="-------------Log Message---------------------"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="FlatFileListener" />
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors &amp; Warnings">
<add name="FlatFileListener" />

I hope the config is self explanatory.It uses a flat file writer which writes into the file log.log present in the root directory.

I usually afraid of these config entries which cannot be memorized by a developer.If you are also afraid of the config entries use the Enterprise Library Configuration Tool.

This is just a sample.There lot more things which we can do with the logging application block such as format the text which is writing into the file.More properties such as priority,category etc…,Variety of logging  locations such as database,email etc…If I get some more extra time I will surely blog about the same.More details can be found in the below links.

NB : Don’t forget to download the CAB and add reference to the following dlls when  you start a new project.

  • Microsoft.Practices.EnterpriseLibrary.Common.dll

  • Microsoft.Practices.EnterpriseLibrary.Logging.dll

  • Microsoft.Practices.ObjectBuilder2.dll

I have uploaded a sample here.

Sunday, January 17, 2010

Finding out which sps are in deadlock in SQL server

When my current Silverlight 3 project went into QA environment, I got one more chance to met my old friend.Yes It’s deadlock.But unfortunately we were not able to reproduce it in the dev environment.There started the problem.
But after a big battle in my dev machine I was able to reproduce the deadlock.Steps were simple.I just need to do the normal operations in the application at lightening speed.
Then we knew its a problem with the WCF service calls from the client to server.There were 2 calls going from client to server while saving where it is supposed to be one by according to the design of the application.But application is in QA.So we tried to resolve that by introducing some mechanisms in the DB.To continue that we needed the information about the SPs which are in deadlock.
Since our application implements the transaction from code and that transaction contains so many sp calls one by one it was very difficult to figure out which sp is in trouble.If we try debug mode there won’t be any deadlock.Finally our DBA given me 2 methods to find out the sps.
The below one give the details about the things happening inside the sql server including the SPID.


Execute the above command in SQL Server Management Studio on your DB.Once you get the SPID use that to find out exactly what is deadlocked in the below method.

dbcc inputbuffer (<SPID>)
I know for a DBA this is not a big thing.But for a developer I think this will help him a lot.