Transaction was deadlocked on lock resources with another process and has been chosen as the deadlock victim....
up vote
0
down vote
favorite
ASP.NET MVC project 4.5 and EntityFramework Database First.
I have some command, which will be triggered when the user clicks a button
using (TransactionScope scope = new TransactionScope())
{
using (DbContext context = new DbContext())
{
//update about 3 tables
scope.Complete();
}
}
In the other hand, I have another method which ONLY read (not updating anything) data from one of the previous tables, but it's working every 2 seconds (there is a timer which triggers this read process).
Problem: sometimes (not always) I am receiving the following exception from the reading process (not the updating process).
System.Data.SqlClient.SqlException: Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
although the update process is working correctly and success and although the read process fails (sometimes not always), which is not a big deal because It will be requested again after 2 seconds and success at that time.
I am afraid that I am not doing it the correct way, Is there any advice to get rid of this exception completely?
NOTE: I was not receiving this exception before, I started to receive this exception when I started to use the TransactionScope
.
Update (Possible Solution)
Actually, I tried to play with the IsolationLevel
as suggested in the comments, Actually, this caused a great reduction in this exception.
I created the Transaction like the following
new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
{
IsolationLevel = IsolationLevel.RepeatableRead
})
NOTE: the level SnapShot
did not work because the database does not support this level.
Update here is the Deadlock profile
c# entity-framework deadlock transactionscope
|
show 3 more comments
up vote
0
down vote
favorite
ASP.NET MVC project 4.5 and EntityFramework Database First.
I have some command, which will be triggered when the user clicks a button
using (TransactionScope scope = new TransactionScope())
{
using (DbContext context = new DbContext())
{
//update about 3 tables
scope.Complete();
}
}
In the other hand, I have another method which ONLY read (not updating anything) data from one of the previous tables, but it's working every 2 seconds (there is a timer which triggers this read process).
Problem: sometimes (not always) I am receiving the following exception from the reading process (not the updating process).
System.Data.SqlClient.SqlException: Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
although the update process is working correctly and success and although the read process fails (sometimes not always), which is not a big deal because It will be requested again after 2 seconds and success at that time.
I am afraid that I am not doing it the correct way, Is there any advice to get rid of this exception completely?
NOTE: I was not receiving this exception before, I started to receive this exception when I started to use the TransactionScope
.
Update (Possible Solution)
Actually, I tried to play with the IsolationLevel
as suggested in the comments, Actually, this caused a great reduction in this exception.
I created the Transaction like the following
new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
{
IsolationLevel = IsolationLevel.RepeatableRead
})
NOTE: the level SnapShot
did not work because the database does not support this level.
Update here is the Deadlock profile
c# entity-framework deadlock transactionscope
why not use the newer,Database.BeginTransaction
also, take a look at isolation level
– TheGeneral
yesterday
1
May be you already read this article - Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)
– ikram
yesterday
@TheGeneral Actually I am considering that but there are some technical problems by using this, I mean no problem, I can apply this, but it will take some time (about an hour to apply it), Are you sure it could solve the problem? if so I can invest in that
– Hakam Fostok
yesterday
@ikram Thank you, I read that article, it is kind of helpful, but It did not give the cure I need.
– Hakam Fostok
yesterday
BeginTransaction
wont solve your problem, and db deadlocks can be caused by very subtle and sometimes non obvious situations, however, from your description, i would try to play around with isolation levels if the transaction has provoked the problem.
– TheGeneral
yesterday
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
ASP.NET MVC project 4.5 and EntityFramework Database First.
I have some command, which will be triggered when the user clicks a button
using (TransactionScope scope = new TransactionScope())
{
using (DbContext context = new DbContext())
{
//update about 3 tables
scope.Complete();
}
}
In the other hand, I have another method which ONLY read (not updating anything) data from one of the previous tables, but it's working every 2 seconds (there is a timer which triggers this read process).
Problem: sometimes (not always) I am receiving the following exception from the reading process (not the updating process).
System.Data.SqlClient.SqlException: Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
although the update process is working correctly and success and although the read process fails (sometimes not always), which is not a big deal because It will be requested again after 2 seconds and success at that time.
I am afraid that I am not doing it the correct way, Is there any advice to get rid of this exception completely?
NOTE: I was not receiving this exception before, I started to receive this exception when I started to use the TransactionScope
.
Update (Possible Solution)
Actually, I tried to play with the IsolationLevel
as suggested in the comments, Actually, this caused a great reduction in this exception.
I created the Transaction like the following
new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
{
IsolationLevel = IsolationLevel.RepeatableRead
})
NOTE: the level SnapShot
did not work because the database does not support this level.
Update here is the Deadlock profile
c# entity-framework deadlock transactionscope
ASP.NET MVC project 4.5 and EntityFramework Database First.
I have some command, which will be triggered when the user clicks a button
using (TransactionScope scope = new TransactionScope())
{
using (DbContext context = new DbContext())
{
//update about 3 tables
scope.Complete();
}
}
In the other hand, I have another method which ONLY read (not updating anything) data from one of the previous tables, but it's working every 2 seconds (there is a timer which triggers this read process).
Problem: sometimes (not always) I am receiving the following exception from the reading process (not the updating process).
System.Data.SqlClient.SqlException: Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
although the update process is working correctly and success and although the read process fails (sometimes not always), which is not a big deal because It will be requested again after 2 seconds and success at that time.
I am afraid that I am not doing it the correct way, Is there any advice to get rid of this exception completely?
NOTE: I was not receiving this exception before, I started to receive this exception when I started to use the TransactionScope
.
Update (Possible Solution)
Actually, I tried to play with the IsolationLevel
as suggested in the comments, Actually, this caused a great reduction in this exception.
I created the Transaction like the following
new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
{
IsolationLevel = IsolationLevel.RepeatableRead
})
NOTE: the level SnapShot
did not work because the database does not support this level.
Update here is the Deadlock profile
c# entity-framework deadlock transactionscope
c# entity-framework deadlock transactionscope
edited yesterday
asked yesterday
Hakam Fostok
5,05583663
5,05583663
why not use the newer,Database.BeginTransaction
also, take a look at isolation level
– TheGeneral
yesterday
1
May be you already read this article - Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)
– ikram
yesterday
@TheGeneral Actually I am considering that but there are some technical problems by using this, I mean no problem, I can apply this, but it will take some time (about an hour to apply it), Are you sure it could solve the problem? if so I can invest in that
– Hakam Fostok
yesterday
@ikram Thank you, I read that article, it is kind of helpful, but It did not give the cure I need.
– Hakam Fostok
yesterday
BeginTransaction
wont solve your problem, and db deadlocks can be caused by very subtle and sometimes non obvious situations, however, from your description, i would try to play around with isolation levels if the transaction has provoked the problem.
– TheGeneral
yesterday
|
show 3 more comments
why not use the newer,Database.BeginTransaction
also, take a look at isolation level
– TheGeneral
yesterday
1
May be you already read this article - Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)
– ikram
yesterday
@TheGeneral Actually I am considering that but there are some technical problems by using this, I mean no problem, I can apply this, but it will take some time (about an hour to apply it), Are you sure it could solve the problem? if so I can invest in that
– Hakam Fostok
yesterday
@ikram Thank you, I read that article, it is kind of helpful, but It did not give the cure I need.
– Hakam Fostok
yesterday
BeginTransaction
wont solve your problem, and db deadlocks can be caused by very subtle and sometimes non obvious situations, however, from your description, i would try to play around with isolation levels if the transaction has provoked the problem.
– TheGeneral
yesterday
why not use the newer,
Database.BeginTransaction
also, take a look at isolation level– TheGeneral
yesterday
why not use the newer,
Database.BeginTransaction
also, take a look at isolation level– TheGeneral
yesterday
1
1
May be you already read this article - Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)
– ikram
yesterday
May be you already read this article - Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)
– ikram
yesterday
@TheGeneral Actually I am considering that but there are some technical problems by using this, I mean no problem, I can apply this, but it will take some time (about an hour to apply it), Are you sure it could solve the problem? if so I can invest in that
– Hakam Fostok
yesterday
@TheGeneral Actually I am considering that but there are some technical problems by using this, I mean no problem, I can apply this, but it will take some time (about an hour to apply it), Are you sure it could solve the problem? if so I can invest in that
– Hakam Fostok
yesterday
@ikram Thank you, I read that article, it is kind of helpful, but It did not give the cure I need.
– Hakam Fostok
yesterday
@ikram Thank you, I read that article, it is kind of helpful, but It did not give the cure I need.
– Hakam Fostok
yesterday
BeginTransaction
wont solve your problem, and db deadlocks can be caused by very subtle and sometimes non obvious situations, however, from your description, i would try to play around with isolation levels if the transaction has provoked the problem.– TheGeneral
yesterday
BeginTransaction
wont solve your problem, and db deadlocks can be caused by very subtle and sometimes non obvious situations, however, from your description, i would try to play around with isolation levels if the transaction has provoked the problem.– TheGeneral
yesterday
|
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370900%2ftransaction-was-deadlocked-on-lock-resources-with-another-process-and-has-been-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why not use the newer,
Database.BeginTransaction
also, take a look at isolation level– TheGeneral
yesterday
1
May be you already read this article - Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)
– ikram
yesterday
@TheGeneral Actually I am considering that but there are some technical problems by using this, I mean no problem, I can apply this, but it will take some time (about an hour to apply it), Are you sure it could solve the problem? if so I can invest in that
– Hakam Fostok
yesterday
@ikram Thank you, I read that article, it is kind of helpful, but It did not give the cure I need.
– Hakam Fostok
yesterday
BeginTransaction
wont solve your problem, and db deadlocks can be caused by very subtle and sometimes non obvious situations, however, from your description, i would try to play around with isolation levels if the transaction has provoked the problem.– TheGeneral
yesterday