Deadlock in WriteLog

Topics: Logging Application Block
Jul 19, 2012 at 9:07 AM

Hi there,

Today, while doing a load test to write Logs in database using Enterprise Library,  I found below error.

 

Tracing

to LogSource 'General' failed.

Processing

for other sources will continue.

See summary information below

for more information.

Should this problem persist

, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories
 

and

sinks.

Summary

for Enterprise Library Distributor Service: ====================================== -->

 

Message:

 

Timestamp:

7/19/2012 12:46:40 PM

Message:

test

Category:

General

Priority:

 -1

EventId:

104

Severity:

Information

Title:

 Machine: DELETED

App

Domain: 7c38d1ea-1-129871557898212980

ProcessId:

6804

Process

Name: C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\WebDev.WebServer40.exe

Thread

Name:

Win32

ThreadId:6212

Extended

Properties:

TimeStamp:

7/19/2012 7:16:47 AM

-->

FullName:

Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

-->

 

AppDomainName: 7c38d1ea-1-129871557898212980 -->

 

WindowsIdentity: INDIA\570537

Exception Information

Details: ======================================

Exception

Type: System.Data.SqlClient.SqlException

 

Errors: System.Data.SqlClient.SqlErrorCollection

 

Class: 13 LineNumber: 56 Number: 1205 Procedure: WriteLog

 

Server: . State: 51

 

Source: .Net SqlClient Data Provider

 

ErrorCode: -2146232060

 Message: Transaction (Process ID 54) was deadlocked on lock resources with another process and has been chosen as the deadlock victim.

 

CODE IS:

Parallel

 

.For(0, 5, y =>

{

 

Task

.Factory.StartNew(() =>

{

 

Logger.Write("test"

);

}

);

});

Please suggest why I am getting this issue...

Jul 19, 2012 at 9:16 AM

 

OMG I am sorry!! In the WriteLog stored proc I modified below line: set @LogID = @@IDENTITY from log to Select @LogID = max(LogID) from Log this caused the problem. Why I changed this line is: @@IDENTITY is a global variable and this will give wrong result when two tables having identity column getting updated at the same time. Now I understood why Enterprise Library Logging\Exception Application Block silent about the returning LOGID to application from database... :D

 

--select @LogID = MAX(LogID) from log  

  --RETURN @LogID

 

SET @LogID = @@IDENTITY

 

 

Jul 19, 2012 at 2:20 PM

Good to hear you resolved your issue.  @@Identity returns the last identity value in the current session so you won't get the identity value inserted by another session.  @@Identity usually works but if you have triggers or replication then you might not get the expected result; in those cases SCOPE_IDENTITY will give the expected result.  

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com