Unanswered: Problems when adding two rows at the same time with C++ using ODBC (SQL-Server)
I'm new to database developing and have the following problem:
I wrote an application in C++ to evaluate and update a database on an SQL-Server using the ODBC-interface. When testing the App using two computers running a test application to fill the Database, i saw that the newly generated data was written with wrong IDs. I found the following problem in my code:
CString cstrFilter = "Select something from ...";
rs.m_strFilter = cstrFilter;
// Filling in the values...
(only an example function to show the prob)
So, now if both computers execute the the rs.AddNew() function at the same time, the newly generated records are generated with the same ID (an auto value), which means, that only one record is written to the database. The table is locked only when the rs.Update() function is called.
I think I'll have to lock the table as soon as possible after opening to prevent this loss of data, but I don't know how.
The calling function includes the db.BeginTrans() and the db.CommitTrans() functions.
It'd be grand if anyone had a suggestion to solve this problem.