I use linq-sql and this is what I need.
Sub Commit()
Try
StepStart:
Transaction Scope Serialized
Begin Transaction
Check BusinessRule1
Check BusinesRule2
if BusinessRulesFailed
{ Transaction.Rollback }
else {
Query = db.out
db.SubmitChanges()
Transaction.Commit()
}
Catch DeadLockException
Goto StepStart
End Try
End Sub
Is it ok to follow this approach? Can someone give me an example in C# or VB.Net
Yes, it’s OK to use this approach. We do something similar. I’d a small delay though, say 500 ms.
With the SQL Server (and Sybase) locking strategy deadlocks will always happen: you can can only reduce the possibility as per MSDN (for 2000 bit still valid). Which also says to retry.
I’ve also seen commercial apps that retry too.
The other option is to enable snapshot isolation which is not perfect though