This is literally my entire transaction:
adc.BeginTransaction();
// create/edit quote assocated with quote request
adc.CreateOrEditQuote(model.QuoteRequestID, model.Amount);
adc.CommitTransaction();
I don't see anywhere that I have an open DataReader
lying around that could be interfering with anything else - there's only one database call inside the transaction! I do have another database call in another class which should be finished by the time this is called:
var model = new ViewQuoteRequestModel();
var qr = DataContextProvider.REDACTED.ListQuoteRequests().SingleOrDefault(q => q.QuoteRequestID == id);
if (null != qr)
{
qr.CopyTo<IViewQuoteRequestModel>(model);
}
return model;
Calling SingleOrDefault
on my data should be resolving it and not leaving it lazy-loaded, right? So that shouldn't be a problem anyway...
edit: if I comment out the line where I call CreateOrEditQuote
then there is no error, but of course the data is not saved. So in case it helps, here is my stored procedure:
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
Weird thing is, if I run the stored procedure manually though SQL Server Management Studio, it runs, but if I do it through my web app (calling the code I shared at the top of my post) it crashes...