I am working in windows application c# MultiThread Functionality(5 Thread) More than 2M data while deleting with my internal code suddenly deadlock error occured help how to rectify and resolve the Problem Error:Transaction (Process ID 59) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction
i refer website and found one query to solve this problem here i mentioned that query but sometimes its not working some time its working SQL: ALTER DATABASE DBName SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE GO
Help how to solve that problem what should i change whether in code or sql Management
Code
if (SqlCon.State == ConnectionState.Closed)
{
OpenConnection();
}
string sqlStmt = "Delete em from Order em inner join OrderHeader ch on ch.CartonId=em.CartonId and ch.OrderNumber = " + "'" + OrderNumber + "'";
SqlCmd.CommandText = sqlStmt;
SqlCommand.CommandTimeout = TimeoutPeriod();
SqlTransaction transaction;
// Start a local transaction.
transaction = SqlCon.BeginTransaction(IsolationLevel.ReadCommitted);
// Must assign both transaction object and connection
// to Command object for a pending local transaction
SqlCommand.Connection = SqlCon;
SqlCommand.Transaction = transaction;
try
{
int val = SqlCommand.ExecuteNonQuery();
// Attempt to commit the transaction.
transaction.Commit();
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
CloseConnection(SqlCon);
}