C# 事务计数不匹配-MARS批处理仍处于活动状态
我在c#应用程序的连接字符串中有C# 事务计数不匹配-MARS批处理仍处于活动状态,c#,stored-procedures,asp.net-core,sqlcommand,C#,Stored Procedures,Asp.net Core,Sqlcommand,我在c#应用程序的连接字符串中有MultipleActiveResultSets=true。我已经知道可以将其设置为false,以防止出现此错误。我正试图找出如何修改存储过程以使用MultipleActiveResultSets=true 所讨论的存储过程是一个相当简单的存储过程,99%的时间都是从C#app执行的,没有问题。但是,有几次,我在它执行时记录了以下错误 EXECUTE后的事务计数表示BEGIN和COMMIT语句的数量不匹配。上一次计数=0,当前计数=1。在MARS批处理中启动的事务
MultipleActiveResultSets=true
。我已经知道可以将其设置为false
,以防止出现此错误。我正试图找出如何修改存储过程以使用MultipleActiveResultSets=true
所讨论的存储过程是一个相当简单的存储过程,99%的时间都是从C#app执行的,没有问题。但是,有几次,我在它执行时记录了以下错误
EXECUTE后的事务计数表示BEGIN和COMMIT语句的数量不匹配。上一次计数=0,当前计数=1。在MARS批处理中启动的事务在批处理结束时仍处于活动状态。事务被回滚
存储过程代码:
begin try
begin transaction
-- create @NewIDs to hold inserted IDs -- hopefully stop any issues related to @@IDENTITY
declare @NewIDs table (MyNewID int)
insert into users
output inserted.id into @NewIDs
values
(
LTRIM(RTRIM(@Username)),
'nothing',
'nothing',
LTRIM(RTRIM(@Email)),
@Phone,
@ProfileID,
LTRIM(RTRIM(@FirstName)),
LTRIM(RTRIM(@LastName)),
LTRIM(RTRIM(@SearchName)),
@Password,
GETDATE()
)
declare @UserID int
select top 1 @UserID = MyNewID from @NewIDs
select @retValue = @UserID
commit transaction
return @retValue
end try
begin catch
if @@TRANCOUNT > 0
rollback transaction
set @retValue = 0
return @retValue
end catch