[英]stored procedure sql server 2008
I am working on a project and am using stored procedure. 我正在一个项目上,正在使用存储过程。 I'm getting this error: 我收到此错误:
Line: 939
Error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid object name 'IT_Assets'.
Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.
Please find below my stored procedure code: 请在下面找到我的存储过程代码:
alter PROCEDURE [ITAssets_sp_IT_Assets]
-- Add the parameters for the stored procedure here
(@Mode varchar(12)='ADD',
@ID integer , @AssetCode nvarchar(20)=null, @Description nvarchar(70)=null,
@Site nvarchar(10)=null)
AS
Begin
IF @Mode='ADD'
Begin
Begin Tran
INSERT INTO [IT_Assets]
([ID]
,[AssetCode]
,[Description]
,[Site])
values
(@ID, @AssetCode, @Description, @Site
)
If @@ERROR <> 0
ROLLBACK TRAN
Else
COMMIT TRAN
Select @ID
End
ELSE
Begin
Begin Tran
UPDATE [IT_Assets]
SET
AssetCode = @AssetCode, Description = @Description, Site = @Site
WHERE ID = @ID
If @@ERROR <> 0
ROLLBACK TRAN
Else
COMMIT TRAN
Select @ID
End
End
I didn't understand the error and I don't know exactly where is the problem? 我不理解错误,也不知道问题出在哪里? Would someone please help me in sloving this problem? 有人可以帮我解决这个问题吗?
From the error Invalid object name 'IT_Assets'
I believe that the table/view 'IT_Assets' is present in a diferent database than the stored procedure (assuming that the object exist and you are using the correct name). 从错误Invalid object name 'IT_Assets'
我认为表/视图“ IT_Assets”与存储过程存在于不同的数据库中(假设该对象存在并且您使用的是正确的名称)。
Then you need to fully quaify it wih Db name like 然后,您需要将Db名称完全量化
UPDATE [DB_NAME].[dbo].[IT_Assets] (assuming `dbo` is the owner)
Try using your database name at top of procedure using use
statement like 尝试在程序顶部使用use
语句使用数据库名称,例如
use [DB_NAME]
GO
alter PROCEDURE [ITAssets_sp_IT_Assets]
-- Add the parameters for the stored procedure here
(@Mode varchar(12)='ADD',
...
Also change you transaction handling using TRY .. CATCH
consruct like below 还可以使用TRY .. CATCH
构造更改您的事务处理,如下所示
Begin Tran
BEGIN TRY
INSERT INTO [IT_Assets]
([ID]
,[AssetCode]
,[Description]
,[Site])
values
(@ID, @AssetCode, @Description, @Site);
COMMIT TRAN;
END TRY
BEGIN CATCH
ROLLBACK TRAN ;
END CATCH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.