Skip to content

Latest commit

 

History

History
104 lines (79 loc) · 5.83 KB

sqlconfigdatasource-function.md

File metadata and controls

104 lines (79 loc) · 5.83 KB
titledescriptionauthorms.authorms.datems.servicems.subservicems.topicf1_keywordshelpviewer_keywordsapilocationapinameapitype
SQLConfigDataSource Function
SQLConfigDataSource Function
David-Engel
davidengel
01/19/2017
sql
connectivity
reference
SQLConfigDataSource
SQLConfigDataSource function [ODBC]
sqlsrv32.dll
SQLConfigDataSource
dllExport

SQLConfigDataSource Function

Conformance
Version Introduced: ODBC 1.0

Summary
SQLConfigDataSource adds, modifies, or deletes data sources.

The functionality of SQLConfigDataSource can also be accessed with ODBCCONF.EXE.

Syntax

 BOOL SQLConfigDataSource( HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes); 

Arguments

hwndParent
[Input] Parent window handle. The function will not display any dialog boxes if the handle is null.

fRequest
[Input] Type of request. The fRequest argument must contain one of the following values:

ODBC_ADD_DSN: Add a new user data source.

ODBC_CONFIG_DSN: Configure (modify) an existing user data source.

ODBC_REMOVE_DSN: Remove an existing user data source.

ODBC_ADD_SYS_DSN: Add a new system data source.

ODBC_CONFIG_SYS_DSN: Modify an existing system data source.

ODBC_REMOVE_SYS_DSN: Remove an existing system data source.

ODBC_REMOVE_DEFAULT_DSN: Remove the default data source specification section from the system information. (It also removes the default driver specification section from the Odbcinst.ini entry in the system information. This fRequest performs the same function as the deprecated SQLRemoveDefaultDataSource function.) When this option is specified, all of the other parameters in the call to SQLConfigDataSource should be NULLs; if they are not NULL, they will be ignored.

lpszDriver
[Input] Driver description (usually the name of the associated DBMS) presented to users instead of the physical driver name.

lpszAttributes
[Input] A doubly null-terminated list of attributes in the form of keyword-value pairs. For more information, see ConfigDSN.

Returns

The function returns TRUE if it is successful, FALSE if it fails. If no entry exists in the system information when this function is called, the function returns FALSE.

Diagnostics

When SQLConfigDataSource returns FALSE, an associated *pfErrorCode value can be obtained by calling SQLInstallerError. The following table lists the *pfErrorCode values that can be returned by SQLInstallerError and explains each one in the context of this function.

*pfErrorCodeErrorDescription
ODBC_ERROR_GENERAL_ERRGeneral installer errorAn error occurred for which there was no specific installer error.
ODBC_ERROR_INVALID_HWNDInvalid window handleThe hwndParent argument was invalid or NULL.
ODBC_ERROR_INVALID_REQUEST_TYPEInvalid type of requestThe fRequest argument was not one of the following:

ODBC_ADD_DSN ODBC_CONFIG_DSN ODBC_REMOVE_DSN ODBC_ADD_SYS_DSN ODBC_CONFIG_SYS_DSN ODBC_REMOVE_SYS_DSN ODBC_REMOVE_DEFAULT_DSN
ODBC_ERROR_INVALID_NAMEInvalid driver or translator nameThe lpszDriver argument was invalid. It could not be found in the registry.
ODBC_ERROR_INVALID_KEYWORD_VALUEInvalid keyword-value pairsThe lpszAttributes argument contained a syntax error.
ODBC_ERROR_REQUEST_FAILEDRequest failedThe installer could not perform the operation requested by the fRequest argument. The call to ConfigDSN failed.
ODBC_ERROR_LOAD_LIBRARY_FAILEDCould not load the driver or translator setup libraryThe driver setup library could not be loaded.
ODBC_ERROR_OUT_OF_MEMOut of memoryThe installer could not perform the function because of a lack of memory.

Comments

SQLConfigDataSource uses the value of lpszDriver to read the full path of the setup DLL for the driver from the system information. It loads the DLL and calls ConfigDSN with the same arguments that were passed to it.

SQLConfigDataSource returns FALSE if it is unable to find or load the setup DLL or if the user cancels the dialog box. Otherwise, it returns the status it received from ConfigDSN.

SQLConfigDataSource maps the System DSN fRequests to the User DSN fRequests (ODBC_ADD_SYS_DSN to ODBC_ADD_DSN, ODBC_CONFIG_SYS_DSN to ODBC_CONFIG_DSN, and ODBC_REMOVE_SYS_DSN to ODBC_REMOVE_DSN). To distinguish user and System DSNs, SQLConfigDataSource sets the installer configuration mode according to the following table. Prior to returning, SQLConfigDataSource resets configuration mode to BOTHDSN. ConfigDSN (implemented by drivers) should call SQLWriteDSNToIni and SQLWritePrivateProfileString to support a system DSN. For more information, see ConfigDSN Function.

fRequestConfiguration mode
ODBC_ADD_DSNUSERDSN_ONLY
ODBC_CONFIG_DSNUSERDSN_ONLY
ODBC_REMOVE_DSNUSERDSN_ONLY
ODBC_ADD_SYS_DSNSYSTEMDSN_ONLY
ODBC_CONFIG_SYS_DSNSYSTEMDSN_ONLY
ODBC_REMOVE_SYS_DSNSYSTEMDSN_ONLY

Related Functions

For information aboutSee
Adding, modifying, or removing a data sourceConfigDSN (in the setup DLL)
Removing a data source name from the system informationSQLRemoveDSNFromIni
Adding a data source name to the system informationSQLWriteDSNToIni
close