Tips for using the atl ole db class in VC to develop access databases

Source: Internet
Author: User
The latest data development technology ole db provided by Microsoft is built on the COM interface. Because ole db is very convenient to develop databases and has fast access to databases, it has become the preferred technology for many commercial software. As a programmer, I have the honor to participate in the development of interactive TV programs of Chengdu World video network Co., Ltd. In the development of the "stock on-demand" system, we chose the ole db class encapsulated by ATL to develop the Stock database. Because the Stock database is usually 100 MB, in addition, the program constantly appends or modifies data to the database, so we have encountered many difficulties in the development process, and fortunately we can solve them one by one. I will discuss some of my experiences and skills in development with you:

1. ole db jet 4.0 is unavailable

At the beginning of the development, because we used the desktop database access, we originally planned to use the ACCESS 2000 database format, but it failed to pass the insert ole db jet 4.0. We try to use ADO technology and directly use the underlying COM interface, and the program can run normally. This indicates that there is no bug in the ole db 4.0 engine, and the problem must be the files generated by the ATL wizard.

Fortunately, I still know the COM technology. after hard work, I finally found the problem: the key is to generate the database header file by the ATL wizard, In the OpenDataSource () function, the following statement is provided:

 

Dbinit. addproperty (dbprop_auth_persist_sensitive_authinfo, false );

 

If we delete it, the program will run normally.

View the dbpropset_dbinit attribute: dbprop_auth_persist_sensitive_authi

"True" or "false" indicates that the database object requires encrypted sensitive authentication information, such as passwords and other encrypted information ". However, we cannot set this parameter to true or false, but only delete it. This may be a bug in the Microsoft ATL template library!

2. Sometimes you need to use the Wizard to generate a header file.

During the development process, we also encountered: If the header file of the database generated using the ATL wizard is used for a long time, errors may occur when the program operates the database! However, after you use the ATL Wizard to regenerate the header file, the program runs normally. However, this occurs in the use of the ole db jet 3.5.1 engine. There is no such problem between using ADO and directly using the underlying COM interface. This may also be a bug in ATL! However, this is not a frequent occurrence and is not easy to find. The database we developed is relatively large, and the program continuously appends or modifies data to the database, so this problem was found during the development process.

3. Determine how to move data to the database header or tail

Because ATL does not provide a function to determine whether the database pointer is moved to the database header or tail, you can only determine whether to move the database pointer to the header or tail Based on the moving function.

The ATL class provides two functions: moveprev and movenext to move the pointer. the return value is of the hresult type. hresult is the 32-bit code returned by an oledb call, the role and meaning of the bit in the code can be found in related books. If the returned value is s_ OK, the pointer is not moved to the database header or tail; otherwise, the pointer is moved to the database header or tail. The following example will traverse the database records: (Info indicates the database record set object)

Hresult hR = info. movefirst ();

While (HR! = S_ OK)

{

// Process the record

HR = info. movenext ()

}

4. If you have changed the header file of the database generated by the ATL wizard, you 'd better rebuild all once, because your changes may affect some ole registration information, it may be necessary to re-compile all files once to update all files. Otherwise, the program may not run properly.

5. Process fields greater than 255 characters.

In the ACCESS database, the reserved field can contain a maximum of 255 characters. What if we want to process a field larger than 255 characters?

We can change the character field to the remarks field. The binding variable of the field generated in the ATL wizard is as follows:

Tchar m_filename [1024]; // a combination of multiple file names

We can see that the mem Field automatically bound to the database by ATL is a string variable, but the character length is limited to 1024 characters. So, can we handle variables larger than 1024 characters? The answer is yes. We only need to change 1024 to the value you need, for example, tchar m_filename [10000]. The program can still run normally. However, we recommend that you use it with caution. Otherwise, unnecessary memory overhead will occur, which is especially important in the development of large commercial databases.

Note: In the debugging version, the variable size cannot exceed 255 characters. If the program uses a variable larger than 255 characters, the correct results may not be obtained in the debugging version, this is normal. If you change to the release version, everything works.

This article only introduces the Problems and Solutions encountered in developing databases using the atl ole db class, hoping to help readers. There are still some bugs in the atl3.0 version integrated with vc6, and we believe it will be solved in future versions. Programmers are also welcomed to discuss vc6 programming skills with me.

Author's blog:Http://blog.csdn.net/ I _like_database/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.