执行存储过程报这种错怎么解决

amwip110 2009-05-13 05:19:44
在WEB系统中执行了一个存储地过程,在存储过程中我建有一临时表,在过程的最后我显示的删除了此临时表,但是报这种错:
There was a transaction active when exiting the stored procedure 'up_RechangePrice'. The temporary table '#__temp1' was dropped in this transaction either explicitly or implicitly. This transaction has been aborted to prevent database corruption.

那位知道是什么原因,怎么解决?(即使把删除临时表的那个语句去掉还是后一样的错)

存储过程如下:
create procedure up_RechangePrice
@PaperNO varchar(16),
@UserNO varchar(20),
@LastUpdateTime datetime
as
begin
create table #__temp1( sStoreNO varchar(12))

declare cursor_store cursor for select sStoreNO from tPriceStore where sPaperNO =@PaperNO

open cursor_store
declare @storeTypeID varchar(2)
declare @storeNO varchar(12)

fetch cursor_store into @storeNO
while (@@sqlstatus=0)
begin
select @storeTypeID = sStoreTypeID from tStore where sStoreNO = @storeNO
if @storeTypeID = '0'
begin
insert into #__temp1
select sStoreNO from tStore where sStoreTypeID = '1'
end
else if @storeTypeID = '3'
begin
insert into #__temp1
select sStoreNO from tStore where sZoneNO=@storeNO and sStoreTypeID = '1'
end
else if @storeTypeID = '1'
begin
insert into #__temp1 values(@storeNO)
end
fetch cursor_store into @storeNO
end

close cursor_store


deallocate cursor cursor_store

insert into tSalePriceRechange(sStoreNO,sPaperNO,nItem,sPRSTypeID,sPRSType,nGoodsID,
dSaleBeginDate,dSaleEndDate,nNewSalePrice,nTag, sCreateUser,
dCreateDate, dLastUpdateTime)
select distinct c.sStoreNO,a.sPaperNO,b.nItem,a.sPRSTypeID,a.sPRSType,b.nGoodsID,
a.dSaleBeginDate,a.dSaleEndDate,b.nNewSalePrice,0,@UserNO,
@LastUpdateTime,@LastUpdateTime
from tPrice a,tPriceDtl b,#__temp1 c
where a.sPaperNO = b.sPaperNO
and a.sPaperNO = @PaperNO

drop table #__temp1
end
...全文
183 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
firefly_2008 2009-05-14
  • 打赏
  • 举报
回复
在創建的時候先判斷一下,如存在則刪除后再創建吧
JIN20468320 2009-05-14
  • 打赏
  • 举报
回复
还有,建议游标少使用,游标使用多的话对系统的消耗是非常大的!建议你看这篇文章
http://www.cnblogs.com/yangtongnet/archive/2009/05/05/1450226.html
JIN20468320 2009-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 pt1314917 的回复:]
建议楼主将临时表改为表变量,就不存在用完后,还要删除临时表的问题了。。
比如:declare @temp table( sStoreNO varchar(12))
[/Quote]
这样做就不必担心删除临时表的问题了!
amwip110 2009-05-14
  • 打赏
  • 举报
回复
存储过程的逻辑有问题吗?好像没有吧!对于3楼的建议我试试。
pt1314917 2009-05-13
  • 打赏
  • 举报
回复
建议楼主将临时表改为表变量,就不存在用完后,还要删除临时表的问题了。。
比如:declare @temp table( sStoreNO varchar(12))
hustsay23 2009-05-13
  • 打赏
  • 举报
回复
按字面翻译就是你执行这个存储过程是在一个事务里面
而你这个存储过程最后把临时表删除了 但是事务没结束 数据库为了防止混乱终止了此次事务

好像事务里面不能建临时表 不晓得你能不能提前建好临时表在执行事务就应该没问题吧
一方晴空 2009-05-13
  • 打赏
  • 举报
回复
你的代码逻辑可能有问题

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧