Replication and autonumber generation issue

Sent: 30 September 2010 22:22
To: [email protected]
Subject: Invoice Number Generation in offline/online database

Hi Venkatesan Prabu


I would like to get your suggestions in regards to invoice number generation in an application that work offline and online

We have a inventory application developed in .net and sql server ,that can work in a LAN by connecting to the server database

Now we need to provide the offline feature for the application, a counter can work independenly without connecting to the server database.i.e, by connecting
to a local copy of the server database

Before the enter any sales data in the counter ,the sales person has to synchronize the data with the server database .to get the stock details and all
Once synchronistation is done,sales bills can be entered from the counter.and in the end of the day or before starting next days work the sales person has to
synchronise the data with the server again.so the Sales details will be available in the server.

The problem here is that the invcoice number generation.Currently the Automatic invoice number is generated using the query

select isNull(Max(BillNumber),0)+1 from PurchaseHeader

If there is more one sales counters that work on local copy of the server database ,the sales billnumber will be duplicated.
because the billNumber is generated from the local database only. when this is uploaded to server there will be duplicate billnumbers

Could you please suggest me some possible solutions to this problem

--
Thanks,
Bijith

Check my Reply for the above problem. Share your thoughts and post some more solutions
Hi Bijith,

Very good practical problem. We can provide multiple solution for your problem.

Below is the best solution for your problem.

1. You need to use Replication for updating your data from local database to master database.
2. In the local database, generate a unique id (Your Invoice number) and amend another unique number (Local counter number). (Your invoice number is 120 and counter id is 20, then the actual invoice number is 12020. The last two number will be unique for your counter).
3. While pushing this data to the master database, generate unique id in the master database and another column will hold the invoice number generated in the local database.

Let me know for any other details needed.

Cheers,
Venkatesan Prabu .J
MVP / MVM / MCITP / MCTS / MCAD / CCNA / QAI
Microsoft SQL Server MVP / Mind Cracker MVP
http://venkattechnicalblog.blogspot.com/