DB and threading
I developed an database application using VC++ and Micorsoft Access driver as the ODBC source. There are 2 threads in the application both accessing the same table. The first thread writes data in the table and the second thread reads and deletes data from the table. Here is a snapshot of the code of the second thread:
while (!attackRecSet->IsEOF())
{
.
.
.
.
.
.
try
{
attackRecSet->Delete();
attackRecSet->MoveNext();
} //try
catch(CDBException *e)
{
MessageBox(NULL, e->m_strError, "Error", MB_OK);
e->Delete();
} //catch
} //while
An error message occurs because of the delete function and the thread stops working. the error message is:
" Could not update; currently locked by user 'admin' on machine ISLAM_COMPUTER'. "
and when I press OK the following message occurs for ever (it reoccurs if I press the OK button):
" Invalid cursor position; no keyset defined. "
If I commented the delete function the thread will work perfectly. I searched the MSDN for an explanation but with no use. Could anyone tell where could I find an explanation for this error.
Islam Hegazy
[1283 byte] By [
islheg] at [2007-11-18 18:35:46]

# 1 Re: DB and threading
well i don't know anything about VC++, but it isn't letting you delete from the table because the table is locked. Maybe your other thread is still writing to the table, or maybe it didn't release the table when it had finished. To maintain data integrity and consistency only one user is allowed to access a particular record at a time so that you can't read something that is in the process of being deleted or updated. I would assume the second error occurs because the delete fails, but again i don't know anything about vc++.