hi all..
i have create a registration form in asp.net & SQL server..
everything was working good..
now the problem is when two user register at same time it'll generate same user ID for both..
the
form will generate user ID when user click "Register" button. Until
they fill up form and click "submit" it'll not save into database.
how can i avoid this problem..?what is the correct method to handle this problem..
Loading
jeeva sanPosted Sep 14, 2010, 9:13 PM
i have an idea...
what about if recheck the "AccNo" from form when i click submit and update ID...
currently i using this sql command to get "AccNo" from database to the form in drop Down List...
SELECT min(AccNo)
FROM (SELECT AccNo + 1 AS AccNo FROM Debtor EXCEPT SELECT AccNo FROM Debtor)
AS newAccNo WHERE AccNo >300000000
-my AccNo start from 300000000
-i already have data in my database more than 2000
if i click "SAVE" button it'll check the "AccNo" in the form with databse and update automatically to new AccNo..
Can anyone help me how to do this...
Imran PervezPosted Sep 14, 2010, 1:16 AM
OR
2 assine user ID When Registration Form Load at user browser and store in session variable
Pasan RatnayakePosted Sep 13, 2010, 4:02 PM
If I have grasped his problem correctly, what actually happens is that when he loads the web page, he creates a new user ID and shows the form where the user enters the rest of the details. This user ID probably looks up the largest user ID and increments it by one for the generation of IDs. Since he does this at the page_load, imagine this scenario.
A user comes in an opens a page and the largest ID in the database is 'UID009' and therefore he creates the new ID as 'UID010' which is written to the form but is not saved anywhere. After that, before this user keys in other data and hit save button, another user opens up the page. When it comes to ID generation, the largest ID is still 'UID009', since 'UID010' is still not saved. Therefore, this user will also get the same ID as the new ID. Now the problem comes when both these users hit the save button. Whoever hits the save button second would try to insert a new record with the same ID which will generate an exception.
A workaround to this system would be to generate the ID when the user hits the save button rather than the page load. When the save button is clicked, generate the ID and insert a new record for that ID along with other data. Therefore, two different saves will have 2 different IDs.
Hope this helps.
Manikavelu VelayuthamPosted Sep 13, 2010, 2:56 AM
Two type of locks are available.
1. Pessimistic Lock
2. Optimistic Lock
Pasan RatnayakePosted Sep 13, 2010, 2:13 AM
You say your problem occurs when you generate the new user id before the user hits the "submit" button. So why don't you generate the user id after the user hits the "submit" button? If it still sound complicated to you, just write code for the following steps in the "Submit" button click event.
1. Generate new user id (Assumption: you always generate a user id that is not in the database)
2. Insert the a new record for that new user id.
My guess is rather than creating random user ids, you are creating user ids that increase by one. Unless the application you are working on is a small scale commercial application or an assignment, I strongly suggest you do it at a database level. Most of the commercial databases and even MS Access provide mechanisms to auto numbering fields which takes care of this problem for you in a much more robust way.
Hope this helps. Regards
jeeva sanPosted Sep 13, 2010, 12:59 AM
I have a registration form in asp.net...
the form will generate "userID" when they click "Sign Up" button..
if two user click "Sign Up" from different place and computer it'll cause error..
Dorababu MekaPosted Sep 13, 2010, 12:53 AM