Tips for developing Access databases using ATL OLE DB class in VC

xiaoxiao2021-03-06  39

Microsoft provides the latest data development technology OLE DB, which is built on the COM interface. Since the OLE DB development database is very convenient, it is a lot of commercial software preferred technologies for many commercial software. As a programmer, I have been fortunate to participate in the development of interactive TV programs in Chengdu Tianxia Video Network Co., Ltd.. In the development of the "stock market" system, we selected the OLE DB class encapsulated by the ATL to develop stock databases. Since the stock database is often 100MB, and the program continues to add or modify the data, we have encountered we encountered in the development process. Less problems, fortunately, can solve one by one. Some experiences and techniques in development are discussed with everyone: 1. OLE DB JET 4.0 cannot use the development of development, because we choose desktop database Access, I originally intended to use Access 2000 database format, but insert OLE DB JET 4.0 is not passed. We tried to use ADO technology and directly using the bottom COM interface, the program can run normally. This shows that the OLE DB 4.0 engine does not have bugs, and the problem must be on the file generated by the ATL wizard. Fortunately, I know more about COM technology. After hard exploration, I finally discovered the problem: the key in the header file of the database, in the OpenDataSource () function in the OpenDataSource () function:

Dbinit.addproperty (dbprop_auth_persist_sensitive_authinfo, false);

If we will delete it, the program can run normally. View dbpropset_dbinit property: dbprop_auth_persist_sensitive_authi nfo means: "True or false represents database objects to adhere to sensitive authentication information such as password and other encrypted information" in the form of encryption. But we will set it to true and false, and only will be deleted. This may be a bug on the Microsoft ATL template library! Second, sometimes you need to reuse the guide to build a header file in the development process: If you use the ATL wizard to generate the header file for a long time, then the program operates the database There may be an error! However, after re-generating the header file with the ATL wizard, the program is running normally. However, this happens in the OLE DB JET 3.5.1 engine, there is no such problem with ADO and direct use of the underlying COM interface, which may be a bug of ATL! But this is not often happening, the user is generally difficult to find. The database we developed is relatively large, and the program continues to add or modify the data to the database, so this problem is found during the development process. Third, how to determine the transfer to the database head or end because there is no determination of whether the database pointer is moved to the database head or tail, so it is determined whether or not the movement is moved or tail. The ATL class provides two functions MovePrev and MoveNext to move pointers. The return value is the HRESULT type. HRESULT is a 32-bit code returned by an OLEDB call. The role of its code and meaning readers can check the relevant books. If the return value is S_OK, indicating that the pointer is not moved to the database head or tail, otherwise it means moving to the database head or tail. The following example will traverse the database record: (INFO representative database record set object) HRESULT HR = info.movefirst (); while (hr! = S_ok) {// Processing the record hr = info.movenext ()} four, if it is changed The header file of the ATL wizard is the header file of the database, preferably REBUILD ALL once, because your changes may affect some OLE registration information, and due to ATL, you may need to re-translate all file information, otherwise, it may cause the program Not working properly. V. Treatment is greater than 255 character fields. The specified characters in the Access database save up to 255 characters, if we want to handle the fields greater than 255 characters? We can change the character field to the note field, and the bound variables of the fields generated in the ATL wizard are as follows : Tchar m_filename [1024]; // Multiple file names combination can see that ATL automatically binds the database MEM type field for us is a string-type variable, but the length of the character is limited to 1024 characters. So, can we handle a variable greater than 1024 characters? The answer is yes, we only need to change 1024 to the value you need, such as tchar m_filename [10000], the program can work normally. However, it is recommended that users use it carefully, otherwise it will cause unnecessary memory overhead, which is especially important in the development of large commercial databases. In addition, you need to explain that in the debug version, the variable uses the character size of more than 255. If the program uses a variable greater than 255 characters, it may not get the correct result in the debug version, which is normal. If you change to the release, everything will be normal. This article is only the skin shaft introduced the issues encountered in the development of database technology in ATL OLE DB, and I hope to help readers. The VC6 integrated ATL3.0 also has some bugs, which is believed to be resolved in future versions. At the same time, welcomes programming enthusiasts to discuss VC6 programming skills.

Author blog: http://blog.9cbs.net/i_like_database/

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

New Post(0)