Export (0) Print
Expand All

SQLDriverConnect

The SQL Native Client ODBC driver defines connection attributes that either replace or enhance connection-string keywords. Several connection-string keywords have default values specified by the SQL Native Client ODBC driver.

For a list of the keywords available in the SQL Native Client ODBC driver, see Using Connection String Keywords with SQL Native Client.

For more information about SQL Server connection attributes and driver default behaviors, see SQLSetConnectAttr.

When the SQLDriverConnect DriverCompletion parameter value is SQL_DRIVER_PROMPT, SQL_DRIVER_COMPLETE, or SQL_DRIVER_COMPLETE_REQUIRED, the SQL Native Client ODBC driver retrieves keyword values from the displayed dialog box. If the keyword value is passed in the connection string and the user does not alter the value for the keyword in the dialog box, the SQL Native Client ODBC driver uses the value from the connection string. If the value is not set in the connection string and the user makes no assignment in the dialog box, the driver uses the default.

SQLDriverConnect must be given a valid WindowHandle when any DriverCompletion value requires (or could require) the display of the driver's connection dialog box. An invalid handle returns SQL_ERROR.

Specify either the DRIVER or DSN keywords. ODBC states that a driver uses the leftmost of these two keywords and ignores the other if both are specified. If DRIVER is specified, or is the leftmost of the two, and the SQLDriverConnect DriverCompletion parameter value is SQL_DRIVER_NOPROMPT, the SERVER keyword and an appropriate value are required.

When SQL_DRIVER_NOPROMPT is specified, user authentication keywords must be present with values. The driver ensures that either the string "Trusted_Connection=yes" or both the UID and PWD keywords are present.

If the DriverCompletion parameter value is SQL_DRIVER_NOPROMPT or SQL_DRIVER_COMPLETE_REQUIRED and the language or database comes from the connection string and either is invalid, SQLDriverConnect returns SQL_ERROR.

If the DriverCompletion parameter value is SQL_DRIVER_NOPROMPT or SQL_DRIVER_COMPLETE_REQUIRED and the language or database comes from the ODBC data source definitions and either is invalid, SQLDriverConnect uses the default language or database for the specified user ID and returns SQL_SUCCESS_WITH_INFO.

If the DriverCompletion parameter value is SQL_DRIVER_COMPLETE or SQL_DRIVER_PROMPT and if the language or database is invalid, SQLDriverConnect redisplays the dialog box.

The following call illustrates the least amount of data required for SQLDriverConnect:

SQLDriverConnect(hdbc, hwnd,
    (SQLTCHAR*) "DRIVER={SQL Native Client};" SQL_NTS, szOutConn,
    MAX_CONN_OUT, &cbOutConn, SQL_DRIVER_COMPLETE);

The following connection strings illustrate minimum required data when the DriverCompletion parameter value is SQL_DRIVER_NOPROMPT:

"DSN=Human Resources;UID=MyUserName;PWD=MyPassword"

"DSN=Human Resources;Trusted_Connection=yes"

"FILEDSN=HR_FDSN;UID=MyUserName;PWD=MyPassword"

"FILEDSN=HR_FDSN;Trusted_Connection=yes"

"DRIVER={SQL Native Client};SERVER=(local);UID=MyUserName;PWD=MyPassword"

"DRIVER={SQL Native Client};SERVER=(local);Trusted_Connection=yes"

Community Additions

ADD
Show:
© 2014 Microsoft