Several methods of registering ODBC data sources

zhaozj2021-02-08  242

Several methods of registering ODBC data sources

National Defense University Dinghao

ODBC (Open Database Connectivity, Open Database Interconnection) is an Application Interface (API) specification. It defines a standard routine set that uses their applications to access data in the data source. The application can use ODBC directly by reference to the API, or use the data access object (DAO) or remote data object (RDO) to use ODBC. However, when implementing ODBC, we must first configure an ODBC environment to register for data sources, so that the data source is connected, accessed, and operations when programming the database. This paper introduces several commonly used methods for registering ODBC data sources. Manual configuration 1. When the ODBC Data Source Manager is developed in the database, in order to achieve the ODBC, the DSN definition registration is performed, Microsoft gives a hand-to-hand solution. In the control panel of the Windows 9x operating system, there is an icon called "ODBC Data Source (32-bit)", which can be activated to set an ODBC environment specifically for users (ODBC Data Source Administrator, ODBC Data Source Manager) . In the Windows 2000 operating system, the above icon is placed inside the "Management Tool" of the control panel. This program for setting an ODBC environment is called a desktop driver that supports several DBMS (Database Management System, Database Management). When the user wants to add a data source and a required driver, you can configure a specific type of database through the Configuration dialog box of the ODBC Data Source Manager. In most cases, when writing a program for database operation, we need at least to know information such as database file name, system (local or remote), folder, and name it to the data source. 2. Define the type of data source that can define the following three types of data sources: user data source: As the user's data source located locally, the user can only be used by users of this data source; system data source: act It is created by a computer or system instead of a specific user's system data source, and the user must have access to access. Document data source: Specify the user-defined user as a file data source, any user who has correctly installed the driver This type of data can be used. 3. The step of data source is as an example. If you create a database file called MyExample.mdb in the C: / MyFile / folder, the registration steps are as follows: Find the "ODBC Data Source" icon in the control panel, Open the interactive interface of the Data Source Manager; the database file created by the author is used by the user on this machine, so select "User DSN" here; then press the "Add" button, in the pop-up data source manager dialog box To select a driver for the data source you want, the database files of this article are created with Microsoft Access, so choose "Microsoft Access Driver (* .mdb)"; after "completing" buttons, enter a title " The interface of the ODBC Microsoft Access Installation, where "Data Source Name" is set to "MyDataSource", select the database file "c: /myfile/myexample.mdb", then OK. In this way, we have completed a simple ODBC data source registration. Of course, in the above steps, users can set different options according to their own different needs.

After the registration is over, we can operate the database in programming. The registration data source in VB is programmed to the database in VB, and the REGISTERDATASOSOURCE method can be utilized to input connection information to the Windows Registry. Its syntax is: RegisterDataSource DSN, DRIVER, SILENT, Attributes The meaning of parameter representatives is: DSN: string expressions, which is the name used when the data source describes the information block. For example, if the data source is an ODBC remote database, this is the name of the server; if it is a user DSN, the name of the registered data source is. Drive: String Expressions indicating the name of the ODBC driver. It is not an ODBC driver dynamic connection library (DLL) file name. For example, SQL Server is the driver name, and SQLSRVR.dll is a DLL file name. ODBC and corresponding drivers must be installed. SILENT: Boolean type value, if you do not want to display the ODBC driver dialog, it is used to specify the information of the driver, which is true; if you want to display the ODBC driver dialog, this value is false. If SILENT is True, Attribute must contain all the required information of the specified driver. Attributes: String Expressions, it is a list of keywords to add to the odbc.ini file. When writing a program, you can set the parameters of several Attributes as needed. For example: We can prepare the following VB program to achieve the same purpose as manually registered above. The list of procedures is as follows: Sub RegisterDataSource () DIM Strattribs As String 'Construction Keyword string. 'C: /myfile/myexample.l.mdb database file name (included path) Strattribs = "dbq =" _ & "c: /myfile/myexample.mdb" _ & chr $ (13) & "Oemtoansi = no" _ & ChR $ (13) & "server = sequel" _ & chr $ (13) & "network = dbnmpntw" _ & chr $ (13) & "database = workdb" _ & chr $ (13) & "address = / / SEQUEL / PIPE / SQL / Query "'Establish a new registered DSN. rdoEngine.rdoRegisterDataSource "mydatasource", "Microsoft Access Driver (* .mdb)", True, strAttribs End Sub Private Sub Form_Load () Call rdoRegisterDataSource End Sub Note: To use rdoEngine and remote data objects in your code, you must first "reference The dialog box sets a reference to the Microsoft Remote Data Object 2.0 object library, otherwise it will cause compilation errors when the RDoEngine object is first referenced.

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

New Post(0)