VB6.0 and database connection (2. Connecting to the database through ADO)

Source: Internet
Author: User
Tags dsn ole

ADO is an easy-to-use application layer interface designed for ole db. It can be said that ADO is a shell of ole db, but not all of the shells are wrapped in ole db, the actual purpose of connecting to the database through ADO is to determine the data provider of ole db. the settings of ADO objects or controls vary according to the data provider of ole db. (The last blog was very miserable, but I think it is very helpful for beginners like me to look at it. So I hope that the readers can look at my previous blog: ADO and Ole
DB and ODBC)

1. Non-ODBC data provider.

At this time, it is the manufacturer of the database management system. According to the ole db standard, a new driver is set up to communicate directly with the database server.

2. ODBC Data Provider

Because the manufacturer of the database management system has not yet produced a Driver Based on ole db, the ODBC standard is used (this standard is earlier, relational databases on the number all have their own drivers). As for the driver connection between ole db and ODBC, we don't have to worry about it, because ole db thinks of this.

When connecting to the ODBC data provider, what we need to do is to create a file with various information that can make the application correctly connect to the database.

2-1. User DSN

After creating a user DSN, the user DSN will save the corresponding configuration information in the Windows registry, but only the login users who create the DSN can use it. For example, VB (User DSN created): objrs. Open ("DNS = dnsname") dnsname indicates the name of the user DSN File we created. The following examples are similar.

2-2. system DSN

The system DSN also saves the related configuration information in the system registry. However, unlike the user DSN, the system DSN allows all users logging on to the server to use it. That is to say, they can only use this computer, OK, you can use the system DSN File. Example: objrs. Open ("DNS = dnsname ")

2-3. File DSN

The specific configuration information of the file DSN is stored in a specific file on the hard disk. The file DSN allows all users who log on to the server to access the database DSN even if no user logs on to the server. In addition, because the file DSN is saved in the hard disk file, it can be easily copied to other machines. In this way, you can directly use the DSN created on other machines without making any changes to the system registry. Example: objrs. Open ("filedns = "). A Represents the location of the hard disk where the file is located.


Insert: when using ODBC standards, you need to configure ODBC. There are two ways to configure ODBC: one is to configure through the ODBC configuration program (the following example shows this method ), the other is to configure data by writing strings. Through the ODBC configuration program, we can clearly know that ODBC is used because of the DSN File. However, it is difficult to distinguish between them through string configuration, character string configuration is to write the configuration in the Code. In fact, the content in the DSN File is these character commands. You can use NotePad to open it (modify the DSN File suffix ), another difficult difference between configuring ODBC and oledb for direct access to (non-ODBC Data Source) databases using strings is that oledb is compatible with ODBC. That is to say, it is also possible to replace some keywords in oledb with those in ODBC, how should we differentiate them? Oledb requires a data source, so there will be providers, while ODBC needs to find the driver provided by the vendor according to the ODBC interface. Therefore, the keyword is driver. The two ODBC configurations are also compatible with each other, that is, your ODBC file is configured with UID and PWD, you can also re-write the UID and PWD in the Code Relay (the UID and PWD in the Code and ODBC file must be the same, or an error occurs). Of course, you can also skip writing.


The following example shows how to create an ADO file:

Start-Control Panel

Select a large icon




Take connecting to the SQL Server database as an Example










OK. Click OK.



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.