Re: Filename with Incrementing Counter

Home Page Forums BizTalk 2004 – BizTalk 2010 Filename with Incrementing Counter Re: Filename with Incrementing Counter

#25715

If you want your application to scale, then SQL Server is the best place to do this. Using multi-threaded host instances on multiple machines will require some mechanism for locking your iterator. I have in the past, used a table with a single column and single row  and a stored proc like this:

DECLARE

 

@increment INT
— need an explicit transaction to make the select and update serializable
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN
TRANSACTION
— ensure that any constraint violations or other errors cause a rollback
SET XACT_ABORT ON
— maintain an exclusive lock on the data until the end of the transaction
SELECT @increment = MAX(Increment) FROM Iterator WITH (TABLOCKX)
UPDATE SaleId SET Increment = @increment + 1
SET XACT_ABORT OFF
COMMIT
TRANSACTION