I am using ODBC API in c++ to connect to a database. I have made my connection function everything worked fine until i got to SQLDriverConnect .
_TUCHAR szConnectOutput[3000];
SWORD nResult;
retcode = SQLDriverConnect(hdbc, NULL,
(SQLTCHAR *)szDNS, SQL_NTS,szConnectOutput, 3000,
&nResult, SQL_DRIVER_NOPROMPT);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode is returned as -1 . I am not sure what the problem is ,it could be my DSN wrong format .
My DNS is DSN=”DSN=Messe10_2;Uid=test;Pwd=test”; .The datebase i am trying to connect is an Oracle database .Is my DSN format wrong ? Or i have some other problem ?
Thanks .
There could be a number of reasons it fails – have you tested the DSN via the ODBC Administrator. Call SQLGetDiagRec when it fails and you’ll find out why. See ODBC Diagnostics & Error Status Codes for examples in C. I cannot see anything obviously wrong given the information you provided e.g., “DSN=x;UID=y;PWD=z” is a valid connection string.