Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Connecting Oracle 19c ODBC using C++

User_AKR7XMay 20 2022

Hi team,
I am very new to Oracle and trying to write a hello world program to connect to the Oracle ODBC through C++ code so that I can get the connection opened and then execute my store procedure. I am using Visual Studio 2017 editor on Windows 10. This is what I am trying to achieve

#include <Windows.h> 
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
int main() {
SQLHANDLE g_sqlEnvHandle;
SQLHANDLE g_sqlConnHandle;
SQLRETURN rc;

/* Allocate the Environment Handle */
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &g_sqlEnvHandle);
/* Set the ODBC version environment attribute */
rc = SQLSetEnvAttr(g_sqlEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
/* Allocate connection handle */
rc = SQLAllocHandle(SQL_HANDLE_DBC, g_sqlEnvHandle, &g_sqlConnHandle);
/* Connect to ODBC driver */
char sConnString_in[2000] = "DRIVER={Oracle in OraDB19Home1};SERVER=localhost;UID=system;PWD=abc;DATABASE=mydataBase";
rc = SQLDriverConnect(g_sqlConnHandle, NULL, (SQLCHAR*)sConnString_in, (SQLSMALLINT)lstrlen((char *)sConnString_in), sConnOut, 200, &cbConnStrOut, SQL_DRIVER_NOPROMPT);
}

On debugging the code, I am always getting -1 from SQLDriverConnect. Any help would be appreciated.
Thank.

Comments

Post Details

Added on May 20 2022
1 comment
1,408 views