Chapter 5. ODBC/CLI Programming

Ability to connect to databases within an ODBC/CLI programming application

[Note]
  • [INFOCENTER_V9] SQLDriverConnect function (CLI) - (Expanded) Connect to a data source

SQLDriverConnect function (CLI) - (Expanded) Connect to a data source

SQLDriverConnect() is an alternative to SQLConnect(). Both functions establish a connection to the target database, but SQLDriverConnect() supports additional connection parameters and the ability to prompt the user for connection information.

Use SQLDriverConnect() when the data source requires parameters other than the 3 input arguments supported by SQLConnect() (data source name, user ID and password), or when you want to use DB2 CLI's graphical user interface to prompt the user for mandatory connection information.

Once a connection is established, the completed connection string is returned. Applications can store this string for future connection requests.

Syntax:

SQLRETURN  SQLDriverConnect (
  SQLHDBC       ConnectionHandle,               /* hdbc */
  SQLHWND       WindowHandle,                   /* hwnd */
  SQLCHAR       *InConnectionString,            /* szConnStrIn */
  SQLSMALLINT   InConnectionStringLength,       /* cbConnStrIn */
  SQLCHAR       *OutConnectionString,           /* szConnStrOut */
  SQLSMALLINT   OutConnectionStringCapacity,    /* cbConnStrOutMax */
  SQLSMALLINT   *OutConnectionStringLengthPtr,  /* pcbConnStrOut */
  SQLUSMALLINT  DriverCompletion);              /* fDriverCompletion */
					

					
printf("\n  Connecting to the database %s ...\n", db1Alias);
sprintf((char *)connStr,
        "DSN=%s; UID=%s; PWD=%s; AUTOCOMMIT=0; CONNECTTYPE=1;",
        db1Alias, user, pswd);

/* connect to a data source */
cliRC = SQLDriverConnect(hdbc,
                        (SQLHWND)NULL,
                         connStr,
                         SQL_NTS,
                         NULL,
                         0,
                         NULL,
                         SQL_DRIVER_NOPROMPT);

					

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     SCDJWS 5.0 Quiz