In my current application, i am performing an update by invoking T-SQL Update command. The problem is when the same record is locked by other users at that time.
At .NET application, the application will wait until SQL Server timeout, then it will throw the SqlException timeout.
Is it possible to perform a check first whether a particular record is locked by other process rather than catching the exception ?
No, not really.
The standard way is to use
try/catchand handleSqlExceptionNumber1205(deadlock victim), and retry your query:[Note: break statements not added for compactness
Also note, many locking issues can be eliminated by providing the appropriate covering indexes.
You can retrieve a complete list of SQL Server’s error messages by querying
sys.messages: