Questions about the database locked and its solution

xiaoxiao2021-03-06  102

When using the MFC and ODBC operational database, different tables generate different CRECORDSET classes, but the database is locked when used.

Solution, don't use the default constructor of CRecordset (no parameters), because of this, the sub-objects inherited from CRecordset are generated by the MFC framework and then pass a cdatabase object to it, this, How many CRecordset sub-objects have, how many cdatabase objects, easy to compete with database resources when using, although in the program is a CRECORDSET sub-class object, then Open another CRecordset, but in the system, the same This may have not completely close, still in a locked state, and another request for connecting the database is here, add SLEEP (TIME (Time (Time (Time) between the two CRecordSet subclass objects. Time)) It can effectively solve this locking approach to confirm this speculation. So we generate a CDATABASE object, and each CRecordset subclass object is generated to use this object as a parameter incoming constructor. In this way, no matter how many CRecordset subclasses (they are mapped to one database), there is only one CDatabase object, there is no competitive resources, not only solve the lock, but also accelerate the running speed of the program!

转载请注明原文地址:https://www.9cbs.com/read-105210.html

New Post(0)