Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2004, 01:12 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default Autogeneration

I am developing an application for purchase orders.
We have different branches all over the world. I want to generate "purchaseorder number" automatically with specific format.

There may be number of users accessing the application continuously.

I am generating the number once the page is accessed. After entering all the details storing in the database. But i have a doubt that at the same time some other is accessing the same page and he also get the same number.

Then PK violation occurs.

How can i over come this problem

Give me solution

Thanx in advance

 
Old January 15th, 2004, 10:27 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you provide more specifics about the order number:
Explain how you are generating it?
The Format?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 15th, 2004, 08:40 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

 The format of purchase order number is (autonumber)

040001

first two digits indicate year
next 4 digits auto increment



 
Old January 16th, 2004, 05:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You could use 2 fields, one for year and one set-up as autonumber, and then just concatenate them when doing a SELECT (Year * 10000 + autonumber).
 
Old January 16th, 2004, 07:29 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The important factor that you need to take into consideration is that you need to generate the order number AFTER the user has entered all the information. Presumably they don't need the order number until they are done creating the details for it. The problem you are having is that a second user can hit the page after a previous user but before that previous user has saved the data. This results in the same order number being generated twice. So you need to create the order number when you save the data to the database. This should eliminate the duplicate problems.

However, something you've said doesn't make sense. You say the purchase order number is "autonumber". If it's an autonumber, then you shouldn't be needing to create it because the database will. And the DB should only create it when you insert new data which is essentially the solution I described above.

Peter
------------------------------------------------------
Work smarter, not harder.









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.