FIX: Msg 267 and 202 on Stored Proc If Table Is Dropped and Re-created

ID: Q192829


The information in this article applies to:

BUG #: WINNT: 18051 (6.5)

SYMPTOMS

A stored procedure with a cursor on a temporary table may fail to execute, with errors 267 and 202, if it references a table that has been dropped and re-created or altered. Following are the messages you may receive:

Msg 267, Level 16, State 1
Object '#tt' cannot be found.
Msg 202, Level 11, State 2
Internal error -- Unable to open table at query execution time.


WORKAROUND

To work around this problem, drop and re-create the procedure.


STATUS

Microsoft has confirmed this to be a problem in SQL Server versions 4.2x and 6.0.

Microsoft has confirmed this to be a problem in SQL Server version 6.5. This problem has been corrected in U.S. Service Pack 5a for Microsoft SQL Server version 6.5. For information about downloading and installing the latest SQL Server Service Pack, see http://support.microsoft.com/support/sql/.

For more information, contact your primary support provider.


MORE INFORMATION

The following small example demonstrates the problem:


create table t1 (i1 int, i2 int)
go

create proc p1 as
declare @i1 int
create table #tt (i1 int)
insert #tt values (1)
declare cc cursor for select i1 from #tt
open cc
fetch cc into @i1
while (@@fetch_status<>-1)
begin
   update t1 set i2=i2+1 where i1=@i1 -- This forces a recompile
   fetch cc into @i1
end
close cc
deallocate cc
select * from #tt -- Raises an error when p1 is invoked for the 2nd time
go

exec p1
go

drop table t1
go
create table t1 (i1 int, i2 int)
go
exec p1  -- Raises 267 error
go
exec p1 -- Raises 202 error 

Additional query words: prodsqlsp sp5message


Keywords          : SSrvStProc kbbug6.50 kbfix6.50.SP5 
Version           : winnt:4.2x,6.0,6.5
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: May 3, 1999