inserting to SQL ASP 3.0

  • Thread starter Thread starter Bruno Alexandre
  • Start date Start date
B

Bruno Alexandre

Hi guys,

I have a web application that insert Clients info into the Database, the
Apllication is accesed by several user at the same time, the Client Info is
divide by 3 tables (Client, Product and 1 that combine the Client and
Product and having all info for how the client bought the product)

My question is: HOW can I know for sure that the script is not accesed by 2
diferent users?

WHY:
The script looks like this
INSERT blablabla INTO tblClients

INSERT blablabla INTO tblProduct

INSERT idClient, idProduct, blablabla INTO tblSales

idClient and idProduct is the @@identity from thoose inserts...

the question is How do I know for sure that tblSales have the right idClient
and idProduct and not from other client that other user is inserting in that
percision time?

I use Application.Lock() and Application.UnLock() before and after I execute
the script, but is this work?


thank you
 
the question is How do I know for sure that tblSales have the right
idClient and idProduct and not from other client that other user is
inserting in that percision time?

Use a stored procedure and surround the INSERT statements with a
transaction.
 
That's why you dont use the AUTONumber/Identity.
Instead use your own table to store the ID.

Call the Key table to get the next ID
Increment the Key table
Use the new ID.

You can get a new key anytime then.
 
@@identity is the identity of the last insert from the current sql batch.
this is thread safe, so no locking is required (unless you stick the value
into a static or vb module variable). you should look at scope_identity(),
because if a trigger inserts into a autonumber table, @@identity will be
that value. scope_identity() is the last assignment in the current scope
(will ingore trigger inserts).

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top