Article ID: 192829 - Last Review: March 14, 2006 - Revision: 4.0

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

This article was previously published under Q192829
BUG #: WINNT: 18051 (6.5)
Expand all | Collapse all

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 6.5. This problem has been corrected in Service Pack 5a for Microsoft SQL Server 6.5.For more information, click the following article number to view the article in the Microsoft Knowledge Base:
197177  (http://support.microsoft.com/kb/197177/ ) INF: How to Obtain SQL Server 6.5 Service Pack 5a
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
				

APPLIES TO
  • Microsoft SQL Server 4.21a Standard Edition
  • Microsoft SQL Server 6.0 Standard Edition
  • Microsoft SQL Server 6.5 Standard Edition
Keywords: 
kbbug kbfix kbsqlserv650sp5fix KB192829
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations