Set the source of ODBC data in program design

xiaoxiao2021-03-06  14

This document will explain how to set an open database connection (ODBC) source name in a program design. This feature will provide you can access the flexibility of the data without the need for forced users to express the ODBC administrator (ODBC administrator) or other programs to specify the source name.

Generally speaking, the user will implement an ODBC administrator program to establish a source of data in the relevant database management system (DBMS) support this job.

When you create a Microsoft Access ODBC source through the ODBC administrator, there are two options: You can choose an existing .mdb file, or create a new .mdb file. You cannot establish a MFC ODBC application in a program design. MDB file. So when your application needs you to place your data in the Microsoft Access Source (.mdb), you will have a very hope that you can have a blank .mdb file that can be used or copied at any time.

However, there are many DBMS that allows the source of data to be established in programming. Certain information sources will maintain a directory specification for the database. That is, the directory is the source of information, and each of the data sources is stored as individual files (if DBASE, each data table is a .dbf file). Other ODBC Database Applicable drivers, such as Microsoft Access, and SQL Server, you need to satisfy certain conditions before establishing a source of data. For example, you must build a SQL Server before using the SQL Server ODBC driver.

SQLConfigDataSource Example

The following examples use :: SqlconfigDataSource ODBC API, create a new Excel data called "New Excel Data Source" Source:

SqlconfigDataSource (NULL, ODBC_ADD_DSN, "Excel Files (* .xls)",

"DSN = New Excel Data Source / 0"

"Description = New Excel Data Source / 0"

"Fileetype = excel / 0"

"DataDirectory = C: // ExcelDir / 0"

"MaxScanRows = 20/0");

Note that the source of this data is actually a directory (C: / ExcelDir); therefore, this directory must be exist. The Excel driver transfers the directory as its data source, and uses the file as an individual data sheet (each .xls file is a data sheet).

For additional information, please refer to the data source: Establish an ODBC data source data sheet file in a program design.

The following information discusses the parameters that needs to be passed to :: SQLConfigDataSource ODBC API. To use: SQLConfigDataSource, you must contain the odbcinst.h header (header file) and use the ODBCINST.LIB to enter the program library. In Run Time, ODBCCP32.DLL (or 16-bit odbcinst.dll) must also be in the path.

You can create an ODBC data source name using an ODBC administrator or similar public program. But sometimes in order to obtain access rights, you'd better build a source of data directly from the application without allowing users to perform a separate public program.

ODBC administrators (usually installed in "console") can log in (or for 16-bit elements, in ODBC.INI file) to establish new sources of information. The ODBC driver administrator will query this file to obtain the source of information. It is very important to know what information to log in to the demand, because you need this information when you are :: SQLConfigDataSource call. Although this information can be written directly from :: SQLConfigDataSource, any technique for any current driver administrator is used to maintain its information. If there is a modified version of the ODBC driver administrator, use different ways to implement a data record that reserves the source of information, any application using this technology will be interrupted. If you have a newer version, you will usually recommend the use of an API letter. For example, if you use a :: SQLConfigDataSource, you can transplanted into a 32-bit program code from 16-bit yuan when you correctly write to an ODBC.ini file or log in.

SQLConfigDataSource parameter

The parameters of the :: SQLConfigDataSource Function will be explained below. For more information, see the ODBC API "Programming Manual provided by version 1.5 and updated Visual C ".

Funitive prototype

Bool SqlconfigDataSource (HWND HWNDPARENT, UINT FREQUEST, LPCSTR LPSZDRIVER, LPCSTR LPSZATTRIBUTES);

Parameter and usage

HWNDParent

This window is specified as any of the relevant information of the relevant information from the user from the user to obtain other new information sources from the user. in case

Lpszattributes parameters do not provide adequate information, a dialogue will appear.

HWndParent parameters can be

NULL; For more information, see Open Database Connection (ODBC) SDK.

LPSZDRIVER

Drive program description. This is the name (ie, DLL) presenting a name (ie, DLL) presenting the name of the user, not the entity driver.

Lpszattributes

A list of properties represented by "keyName = value". These places will be partitioned in the NULL Terminal, and the end of the list will be represented in two consecutive NULL terminals. These attributes are mainly preset driver specific projects, which will become login information from the source of new information. The DBC API reference version has an important key that has not been mentioned, that is, you can specify the DSN of the Source Name of the New Data (Source Name "). Other parts of the project are dedicated to the drivers of the source of new information. Since the driver will require a new value to the user in the dialogue, all items are usually required (will

HWndParent setting

NULL to achieve this purpose). You can express the preset value clearly, so that users will not receive this requirement.

To determine the driver program description of the LPSZDRIVER parameter using the ODBC administrator program

Execute an ODBC administrator program. Press [Joining].

You will get a list of installed drivers and their descriptions. This instructions are used as the LPSZDRIVER parameter. Note that you need to use the entire description, such as "Excel Files (* .xls)", including the sideline name and parentheses that may appear in the description.

Another practice is that you can check the login (for 16-bit yuan, it is in the ODBCINST.INI file), which contains a list of all driver projects, and "ODBC Drivers" under registry key. Description (or [ODBC Drivers] section in the ODBCINST.INI file).

One way to find the key names and values ​​of the lpszattributes parameter is an ODBC.ini file that checks a set data that has been set (probably completed by the ODBC Administrator program: To find the key name and value of the lpszattributes parameter

Execute a Windows login editor (if it is for 16-bit yuan, turn on the ODBC.INI file). Use one of the following to find ODBC information source.

If you are 32-bit yuan, look for the HKEY_CURRENT_USER / SOFTWARE / ODBC / ODBC.INI / ODBC Data Source code in the left pane. The right pane is listed in the form item: pub: reg_sz: , where is a source of setting with the required settings you want to use. Select the source of information you want to use, such as SQL Server. Picking in the PUB: The item after the string is in accordance with the order, the key name and the value used in your LPSzattributes parameter. If it is 16-bit yuan, look for a section of the [] flag in the ODBC.INI file. The line of rows after this line is "keyname = value". These are actually used in projects in your LPSzattributes parameter.

You may also need to check the specific driver file you will use. You can perform an ODBC administrator with useful information for this driver in the instructions. These instructions files are usually placed in the Windows / System directory on Windows NT, Windows 3.1 or Windows 95.

To get the line of your ODBC driver

Execute an ODBC administrator. Press [Joining]. Select the driver name. Please click [OK].

Please click [Description] when the ODBC administrator displays the specific driver information for the establishment of a new source of data. This can be opened in this particular driver, which typically contains important information using the driver.

For related information, see the Open Database Connection (ODBC) SDK

See

Source (ODBC)

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

New Post(0)