这实际上是我的整个交易:
adc.BeginTransaction();
// create/edit quote assocated with quote request
adc.CreateOrEditQuote(model.QuoteRequestID, model.Amount);
adc.CommitTransaction();
[我看不到任何地方都有开放的DataReader
,这可能会干扰其他任何事情-事务内部只有一个数据库调用!我确实在另一个类中有另一个数据库调用,应该在调用它时完成:
var model = new ViewQuoteRequestModel();
var qr = DataContextProvider.REDACTED.ListQuoteRequests().SingleOrDefault(q => q.QuoteRequestID == id);
if (null != qr)
{
qr.CopyTo<IViewQuoteRequestModel>(model);
}
return model;
在我的数据上调用SingleOrDefault
应该可以解决它,而不是让它延迟加载,对吗?所以无论如何这都不应该成为问题...
编辑:如果我注释掉我呼叫CreateOrEditQuote
的行,则没有错误,但是当然不会保存数据。因此,如果有帮助,这是我的存储过程:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[REDACTED].[CreateOrEditQuote]') AND type in (N'P', N'PC'))
DROP PROCEDURE [REDACTED].[CreateOrEditQuote]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [REDACTED].[CreateOrEditQuote]
(
@QuoteRequestID int,
@Amount money
)
as
begin
declare @qid int
select @qid = QuoteID from QuoteRequest where ID = @QuoteRequestID
if @qid is null
begin
-- quote does not exist, create it
insert into quote (Amount) values (@Amount)
select @qid = @@IDENTITY
end
else
begin
-- quote exists, edit it
update quote set Amount = @Amount where ID = @qid
end
update QuoteRequest set QuoteID = @qid where ID = @QuoteRequestID
select @qid as QuoteID
end
GO
奇怪的是,如果我通过SQL Server Management Studio手动运行存储过程,它就会运行,但是如果我通过Web应用程序(调用我在文章顶部共享的代码)来执行存储过程,则会崩溃...] >
这实际上是我的整个交易:adc.BeginTransaction(); //创建/编辑与报价请求adc.CreateOrEditQuote(model.QuoteRequestID,model.Amount)相关联的报价; adc.CommitTransaction(); ...
因为我的存储过程正在返回数据,所以我不得不检索该数据: