transactions / locking tables

omart

Member
Joined
Jul 6, 2008
Messages
13
Programming Experience
1-3
Hi,

I have a program that connectst to a database, ultimately, after a button is pushed it looks for the largest number(in a specific column), increments it and add the row, than returns that number, and a msg box displays the new number.

i have one dll that handles all the connection stuff but, i have two different programs that access this dll, that basically do the same ting (to get the new incremented number)

My problem is, if i push the buttons fast enough on both programs, both message boxes will display the same number, but only one gets added to the database, prob because this column is also the primary key.

My question is, what is the best way of handling this, i am trying to read on transactions or locking the databse some how but im not sure

thanks
 
we tend to use proper databases like oracle, that have things like sequences, that don't do that sort of thing..

SELECT MAX(id)+1 will always be a bad way of implementing an autonumber.. don't do it
 
ok ic, unfortunetly im on sql...express...but thanks to your sugestion i found the identity property, seems like it is working ok for now, but i got to do more testing.

one more question, when doing queries to the database is is best to run them using threads? or is that just a matter of preference. right now i dont want the user to be able to do anything while it is q'ing DB.
 
Back
Top