Connecting to InterSystems Cloud Services with ODBC
See how to connect to InterSystems Cloud Services from your C++ application, using the InterSystems ODBC Driver.
See how to connect to InterSystems Cloud Services from your C++ application, using the InterSystems ODBC Driver.
To connect to InterSystems Cloud Services, copy the code below and modify it to include your system's information and point to your ODBC driver:
#ifdef WIN32 #include <windows.h> #endif #include <sqlext.h> #ifdef UNICODE #include <sqlucode.h> #endif #include <stdio.h> int main() { RETCODE rc; /* Return code for ODBC functions */ HENV henv = NULL; /* Environment handle */ HDBC hdbc = NULL; /* Connection handle */ unsigned char szOutConn[600]; SQLSMALLINT *cbOutConn = 0; SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0); SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); char connect_cmd[255] = "Driver=InterSystems IRIS ODBC35;Host=localhost;Port=1972;Database=USER;UID=SQLAdmin;PWD=deployment-password;\0"; rc = SQLDriverConnect(hdbc, NULL, (SQLCHAR*) connect_cmd, SQL_NTS, szOutConn, 600, cbOutConn, SQL_DRIVER_COMPLETE); if (rc == SQL_SUCCESS) { printf("Successfully connected!!\n"); } else { printf("Failed to connect to IRIS\n"); exit(1); } SQLDisconnect(hdbc); SQLFreeHandle(SQL_HANDLE_DBC, hdbc); /* Free connection handle */ SQLFreeHandle(SQL_HANDLE_ENV, henv); /* Free environment handle */ return 0; }
See other ways to connect to InterSystems Cloud Services (resource guide).
Having an issue with the learning site? Want to provide feedback on a course? Contact us by emailing online.training@intersystems.com.
Please include all relevant information, including the page or course you are having trouble with, and any necessary screenshots.