Reputation: 1637
I have transaction scope and I would like to:
using (var scope = new TransactionScope())
{
1) Insert row into table1
2) Select rows from table1 (incuding inserted row in step 1)
3) Insert another row into table1
4) Select rows from table1 (incuding inserted row in step 1 and 3)
}
Is there any chance to get a sql deadlock in those operations? I'm usig Entity Framework for Db work. I'm not sure about this.
Thank you,
Have a nice day.
Upvotes: 0
Views: 874
Reputation: 16067
There should be no problems with this.
The inserts may lock other users out, or even lock other transactions made by yourself, but it does not lock you from doing anything in the same Sql transaction.
Upvotes: 1
Reputation: 425251
Yes, it's possible for a deadlock for occur.
If SQL Server
chooses to escalate locks required by INSERT
operations to page or table level and this scenario occurs:
Transaction 1 Transaction 2
INSERT INTO page1
INSERT INTO page2
INSERT INTO page1
INSERT INTO page2
then the two transactions will deadlock and one of them will have to be rolled back.
Upvotes: 0