views:

125

answers:

0

Hi, I am getting Sql deadlocks while calling aspnet_Users_CreateUser Api during load test (100+ concurrent users) I have wrapped the createUser, roles.AddUserToRole and another custom mapping procedure inside a Transaction Scope block. Once the deadlock is encountered no more user accounts are created. I am also using Enterprise Library to log exceptions. How do I take care of the Sql deadlocks?

Your inputs are much appreciated. Below is a sample of my code with the stack trace.

Thank you,
sosmary

enter code here1.

Try  
 Using scope as new TransactionScope  
  Dim usr As MembershipUser = Membership.CreateUser(.....)  
  If not usr is Nothing Then  
   If createFlag = MembershipCreate.Success Then  
   Roles.AddUserToRole(usr.Username, "CustomerRep")  
    MapUser(usr.UserId)  'insert into a custom mapping table, usr.UserId is foreign   key in this table  
    scope.Complete()  
  Endif  
 Endif  
End Using    
Catch ex as Exception  
'Call ExceptionHandling to log exceptions  
'Show error message   
End Try

Below is the error message with the stack trace.

enter code here *# Summary for Enterprise Library Distributor Service:

======================================

-->

*# Message:
*# Timestamp: 11/25/2009 8:14:22 AM
*# Message: HandlingInstanceID: 7effc3f6-80ce-427f-a320-b96d2daededa
*# An exception of type 'System.Data.SqlClient.SqlException' occurred and was caught.

----------------------------------------------------------------------------------

*# 11/25/2009 03:14:21
*# Type : System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, *Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Transaction (Process ID 118) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
*# Source : .Net SqlClient Data Provider
*# Help link :
*# Errors : System.Data.SqlClient.SqlErrorCollection
*# Class : 13
*# LineNumber : 19
*# Number : 1205
*# Procedure : aspnet_Users_CreateUser
*# State : 48
*# ErrorCode : -2146232060
*# Data : System.Collections.ListDictionaryInternal
*# TargetSite : Void OnError(System.Data.SqlClient.SqlException, Boolean)
*# Stack Trace : at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, *Boolean breakConnection)
*# at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, *Boolean breakConnection)
*# at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject *stateObj)
*# at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand *cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, *TdsParserStateObject stateObj)
*#at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior *runBehavior, String resetOptionsString)
*# at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, *RunBehavior runBehavior, Boolean returnStream, Boolean async)
*# at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, *RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
* at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, *String methodName, Boolean sendToPipe)
* at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
* at System.Web.Security.SqlMembershipProvider.CreateUser(String username, String *password, String email, String passwordQuestion, String passwordAnswer, Boolean *isApproved, Object providerUserKey, MembershipCreateStatus& status)
* at System.Web.Security.Membership.CreateUser(String username, String password, String *email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object *providerUserKey, MembershipCreateStatus& status)
* at System.Web.Security.Membership.CreateUser(String username, String password, String *email, String passwordQuestion, String passwordAnswer, Boolean isApproved, *MembershipCreateStatus& status)
* at Membership_RegNew.btnSubmit_Click(Object sender, EventArgs e)