Understanding and Avoiding Blocking

Blocking happens when one connection from an application holds a lock and a second connection requires a conflicting lock type. This forces the second connection to wait, blocked on the first. One connection can block another connection, regardless of whether they emanate from the same application or separate applications on different client computers.


Note Some of the actions needing locking protection may not be obvious, for example, locks on system catalog tables and indexes.


Most blocking problems happen because a single process holds locks for an extended period of time, causing a chain of blocked processes, all waiting on other processes for locks.

Common blocking scenarios include:

SQL Server is essentially a puppet of the client application. The client application has almost total control over (and responsibility for) the locks acquired on the server. While the SQL Server lock manager automatically uses locks to protect transactions, this is directly instigated by the query type sent from the client application and the way the results are processed. Therefore, resolution of most blocking problems involves inspecting the client application.

A blocking problem frequently requires both the inspection of the exact SQL statements submitted by the application and the application’s exact behavior regarding connection management, processing of all result rows, and so on. If the development tool does not allow explicit control over connection management, query time-out, processing of results, and so on, blocking problems may not be resolvable.

Guidelines for designing applications to avoid blocking include:

See Also
Deadlocking Locking

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.