B
Ben Fidge
I've written a system using ADO.NET that comprises two ASP.NET applications
running on different servers but accessing the same Sql Server 2000
database.
The first application is an intranet based booking system for taking orders
over the phone, and the other is an internet based e-commerce application
placing bookings in the same tables as the first application.
When a booking is placed it is assigned a reference number which is a simple
sequence number stored in a table called Admin, as an integer field called
Last_Allocated_TicketNumber.
Very rarely two bookings are placed at precisely the same time and get
assigned the same reference number from the Admin table. The stored
procedure that updates the Last_Allocated_TicketNumber is defined as so:
CREATE PROCEDURE dbo.prcBookings_GetNewTicketNo
@aTicket_No int output
AS
select @aTicket_No = Last_Allocated_TicketNumber from Admin;
select @aTicket_No = @aTicket_No + 1;
update Admin set Last_Allocated_TicketNumber = @aTicket
How can I prevent this from happening, and temporarily lock the record while
it's being updated? I know ADO.NET doesn't support pessimistic locking. I'm
using SqlTransactions, as a few other tables get updated at the same time,
and I use the default IsolationLevel of ReadCommitted.
Kind regards
Ben
running on different servers but accessing the same Sql Server 2000
database.
The first application is an intranet based booking system for taking orders
over the phone, and the other is an internet based e-commerce application
placing bookings in the same tables as the first application.
When a booking is placed it is assigned a reference number which is a simple
sequence number stored in a table called Admin, as an integer field called
Last_Allocated_TicketNumber.
Very rarely two bookings are placed at precisely the same time and get
assigned the same reference number from the Admin table. The stored
procedure that updates the Last_Allocated_TicketNumber is defined as so:
CREATE PROCEDURE dbo.prcBookings_GetNewTicketNo
@aTicket_No int output
AS
select @aTicket_No = Last_Allocated_TicketNumber from Admin;
select @aTicket_No = @aTicket_No + 1;
update Admin set Last_Allocated_TicketNumber = @aTicket
How can I prevent this from happening, and temporarily lock the record while
it's being updated? I know ADO.NET doesn't support pessimistic locking. I'm
using SqlTransactions, as a few other tables get updated at the same time,
and I use the default IsolationLevel of ReadCommitted.
Kind regards
Ben