这是我的存储过程代码
ALTER procedure [Proc_Add_User]
(@UserId varchar(20),
@UserName varchar(100),
@Page_Name varchar(20),
@AccessIndicator int,
@CreatedBy varchar(50),
@returnStatus varchar(50) output)
as
DECLARE @intErrorCode INT
DECLARE @Page_Indicator INT
begin
BEGIN TRAN
Set @Page_Indicator = (select Page_Indicator from Pages where Page_Name=@Page_Name);
if (select count(*) from Users where UserId=@UserId and UserName=@UserName) > 0 begin
if (select count(*) from User_Credentials where Page_Indicator=@Page_Indicator and
UserId=@UserId ) > 0
set @returnStatus='User already has access'
else
insert into User_Credentials(UserId,Page_Indicator,Access_Indicator,CreatedBy)
values (@UserId,@Page_Indicator,@AccessIndicator,@CreatedBy)
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
end
else begin
insert into Users(UserId,UserName,CreatedBy)
values(@UserId,@UserName,@CreatedBy)
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
insert into User_Credentials(UserId,Page_Indicator,Access_Indicator,CreatedBy)
values (@UserId,@Page_Indicator,@AccessIndicator,@CreatedBy)
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM
end
COMMIT TRAN
if(@returnStatus is null)
set @returnStatus='Success';
PROBLEM:
IF (@intErrorCode <> 0) BEGIN
set @returnStatus= 'Unexpected error occurred!'
ROLLBACK TRAN
end
end
我从下面粘贴的代码中调用它:
Con.Open();
cmd = new OleDbCommand();
cmd.Connection = Con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Proc_Add_User";
cmd.Parameters.Clear();
cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = userLanId;
cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = userName;
cmd.Parameters.Add("@Page_Name", SqlDbType.VarChar).Value = pageName;
cmd.Parameters.Add("@AccessIndicator", SqlDbType.Int).Value = accessIndicator;
cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = createdBy;
OleDbParameter output = new OleDbParameter("@returnStatus", SqlDbType.VarChar);
output.Direction = ParameterDirection.Output;
cmd.Parameters.Add(output);
int result = cmd.ExecuteNonQuery();
我收到ExecuteNonQuery
声明中提到的错误。令我困惑的是我能够在 SSMS 中执行存储过程,但不能从我的应用程序(前端)执行。我也提供了相同的值,但它在我的应用程序中失败了。
我仔细检查以确保传递的参数的顺序匹配并且具有相同的数据类型,但仍然会引发此错误。如果需要,我可以在此处粘贴我存储的 proc 代码,所以请告诉我..提前致谢!
编辑
哎呀!我刚刚意识到所有的插入都在发生并且在数据库中得到很好的提交。只是这个错误在我的应用程序的 catch 块中被捕获。有任何想法吗?
我不能忽略它,因为基于 ExecuteNonQuery() 的返回值,我有一些语句,而且它没有通过 ExecuteNonQuery() 之后的代码。