SQLConnect function establishes the connection to a database using an existing ODBC data source, user name and password.
Quick Example:
// Connect to Oracle SQLRETURN retcode = SQLConnect(hdbc, "oracle_dsn", SQL_NTS, "scott", SQL_NTS, "tiger", SQL_NTS);
Conversion issues:
Last Update: Microsoft SQL Server 2012 and Oracle 11g
When you connect to Oracle using Oracle ODBC driver (sqora32.dll), the SQLConnect() function returns SQL_SUCCESS when the connection is successful.
At the same time, if you use SQL Server Native Client (native SQL Server ODBC driver) to connect to SQL Server, it returns SQL_SUCCESS_WITH_INFO when the connection is successful, and the message text contains:
"[Microsoft][SQL Server Native Client 11.0][SQL Server]Changed database context to 'master'."
Note. SQL_SUCCESS_WITH_INFO is returned even if you do not specify to change the default database in the SQL Server ODBC driver settings.
If your Oracle application checks SQL_SUCCESS after calling SQLConnect(), you have to change the code to also check for SQL_SUCCESS_WITH_INO, or just check for a value >= 0 for a successful connection, and < 0 for failed connection:
Oracle:
// Connect to Oracle SQLRETURN retcode = SQLConnect(hdbc, "db_dsn", SQL_NTS, "scott", SQL_NTS, "tiger", SQL_NTS); // Check if connection failed if(retcode != SQL_SUCCESS) { // ... exit } // Check if connection successful if(retcode == SQL_SUCCESS) { // ... continue processing }
SQL Server and SQL Azure:
// Connect to SQL Server SQLRETURN retcode = SQLConnect(hdbc, "db_dsn", SQL_NTS, "scott", SQL_NTS, "tiger", SQL_NTS); // Check if connection failed if(retcode < SQL_SUCCESS) // changed != to < { // ... exit } // Check if connection successful if(retcode >= SQL_SUCCESS) // changed == to >= { // ... continue processing }
SQLines ODBC driver supports the following conversion features for SQLConnect() function:
Using SQLines ODBC driver you do not need to modify existing Oracle ODBC applications that use SQLConnect() function. More...