我有存儲過程,我在其中有一個事務。錯誤:ROLLBACK TRANSACTION請求沒有相應的BEGIN TRANSACTION
當我與SQL Server Management Studio中執行它沒有錯誤,但是當我用我的C#代碼執行它出現以下錯誤:
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
的代碼是:
CREATE PROCEDURE [dbo].[AddHardDisk]
@name nvarchar(50), @brand nvarchar(50), @serial nvarchar(50), @cost float, @seller nvarchar(50),@note nvarchar(1000),@buyDate Date,
@size int ,@moneyType nvarchar(50)
AS
DECLARE @addedDeviceID int
BEGIN TRY
BEGIN TRAN
insert into Product(Name,Brand,Serial,Cost,Seller,Note,MoneyType,BuyDate)
values(@name,@brand,@serial,@cost,@seller,@note,@moneyType,@buyDate)
select @addedDeviceID =SCOPE_IDENTITY()
insert into HardDisk(ID,size)
values(@addedDeviceID,@size)
exec DecreaseMoneyFromFund @moneyType,@cost
COMMIT
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK
END CATCH
你可以發佈你的C#代碼調用這個存儲過程的相關部分嗎? DecreaseMoneyFromFund過程也在做什麼? – abhi
你能否發佈'DecreaseMoneyFromFund'的源代碼? –
問題出現在SQL中,而不是C# – wruckie