RogerGarrett
February 3rd, 2006, 07:14 PM
I'm doing some queries on a SQL Server 2000 database. (MFC C++ dialog-based application).
I start up a transaction with:
m_Session.StartTransaction(ISOLATIONLEVEL_SERIALIZABLE)
I then do a query that determines whether or not a particular item is in a particular table. If it's already there I then do a query which UPDATEs the existing item. If it's not already there I do an INSERT query. If everything goes OK I do a m_Session.Commit(), otherwise I do a m_Session.Abort().
However, this is done within a thread. There can also be another thread doing the exact same thing for the exact same item in the table. It was my understanding that specifying ISOLATIONLEVEL_SERIALIZABLE in the StartTransaction call assures that the two threads don't interfere within one another, and that when one thread determines that the item does not exist and proceeds to do an INSERT, it's not possible that at the same time the other thread has just done the same thing but already performed the INSERT.
But it doesn't behave as I had expected. I do indeed get clashes between the two threads.
It appears I need some way to tell it to "lock" specific tables, or maybe even specific items in the tables, in order to asure that my two threads don't clash.
What is the proper way to do this?
Roger Garrett
I start up a transaction with:
m_Session.StartTransaction(ISOLATIONLEVEL_SERIALIZABLE)
I then do a query that determines whether or not a particular item is in a particular table. If it's already there I then do a query which UPDATEs the existing item. If it's not already there I do an INSERT query. If everything goes OK I do a m_Session.Commit(), otherwise I do a m_Session.Abort().
However, this is done within a thread. There can also be another thread doing the exact same thing for the exact same item in the table. It was my understanding that specifying ISOLATIONLEVEL_SERIALIZABLE in the StartTransaction call assures that the two threads don't interfere within one another, and that when one thread determines that the item does not exist and proceeds to do an INSERT, it's not possible that at the same time the other thread has just done the same thing but already performed the INSERT.
But it doesn't behave as I had expected. I do indeed get clashes between the two threads.
It appears I need some way to tell it to "lock" specific tables, or maybe even specific items in the tables, in order to asure that my two threads don't clash.
What is the proper way to do this?
Roger Garrett