BUG: "SET TRANSACTION ISOLATION LEVEL" Ignored in Stored Proc (171322)
The information in this article applies to:
This article was previously published under Q171322
BUG #: 17076
SYMPTOMS
If you code "SET TRANSACTION ISOLATION LEVEL <option>" within a stored
procedure, the statement is ignored during the execution of that stored
procedure. The isolation level in effect for the connection that first
executes the stored procedure will be used during all subsequent executions
of that procedure plan, even if a subsequent connection is using a
different isolation level when it calls the relevant stored procedure.
Also, the connection that issues the CREATE PROCEDURE statement will have
its transaction isolation level set to whatever <option> is coded for the
"SET TRANSACTION ISOLATION LEVEL <option>" statement within the procedure.
CAUSE
The SET TRANSACTION ISOLATION LEVEL <option> that is contained in the
CREATE PROCEDURE statement is executed as if it were coded outside of the
procedure. However, the CREATE PROCEDURE statement executes without
indicating any problem, (unless the SET statement is the only statement in
the procedure, in which case you get error 124: "CREATE PROCEDURE contains
no statement").
Furthermore, the transaction isolation level associated with the connection
that first executes the relevant stored procedure is set during all
subsequent executions of that procedures execution plan.
WORKAROUND
To work around this problem, do one of the following:
- If the requirement is to set the transaction isolation level to READ
UNCOMMITTED within your stored procedure, use the optimizer hint NOLOCK
in your SELECT statements within the stored procedure.
- Do not set the transaction isolation level anywhere in your code. The
default transaction isolation level, READ COMMITTED, will then be
used consistently within all stored procedures.
- Use the WITH RECOMPILE option on the CREATE PROCEDURE statement. Then
execute the SET TRANSACTION ISOLATION LEVEL <option> statement before
calling the stored procedure.
- Execute the SET TRANSACTION ISOLATION LEVEL <option> statement before
calling the stored procedure. Then use the WITH RECOMPILE option when
invoking the stored procedure. Be aware that this causes multiple copies
of the stored procedure plan to be kept in the procedure cache.
STATUS
Microsoft has confirmed this to be a problem in Microsoft SQL Server
version 6.5. We are researching this problem and will post new information
here in the Microsoft Knowledge Base as it becomes available.
Modification Type: | Major | Last Reviewed: | 10/3/2003 |
---|
Keywords: | kbBug kbusage KB171322 |
---|
|