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.