#include <windows.h> #include <stdio.h> #define ODBCVER 0x0210 #include <sql.h> #include <sqlext.h> void ODBCError(SQLHENV hEnv) { SDWORD nativeError=0; SQLCHAR szSqlState[100]; SQLCHAR szOdbcMsg[2048 + 1]; SWORD cbOdbcMsg=0; RETCODE retcode; while ((retcode = SQLError(hEnv,NULL,NULL,szSqlState,&nativeError, szOdbcMsg, 2048, &cbOdbcMsg))==SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { szOdbcMsg[cbOdbcMsg]='\0'; printf("%s,%d, %s\n",szSqlState,(int)nativeError,szOdbcMsg); } } DWORD HandleException(DWORD exceptioncode) { printf("\tException is thrown:0x%08X <---------------!!!\n",(int)exceptioncode); return EXCEPTION_EXECUTE_HANDLER; } void main(void) { SQLHENV hEnv=NULL; SQLHDBC hDbc=NULL; SQLHSTMT hStmt=NULL; RETCODE retval=SQL_SUCCESS; BOOL fConnected=FALSE; SQLSMALLINT nOutLen=0; SQLCHAR sConnectString[1024]; retval=SQLAllocEnv(&hEnv); if(!SUCCEEDED(retval) || !hEnv) { printf("SQLAllocEnv failed.\n"); goto exitproc; } retval=SQLAllocConnect(hEnv,&hDbc); if(!SUCCEEDED(retval) || !hDbc) { ODBCError(hEnv); printf("SQLAllocConnect failed.\n"); goto exitproc; } printf("Trying to connect ...\n"); retval=SQLDriverConnect(hDbc,GetDesktopWindow(),(SQLCHAR*)"",SQL_NTS,sConnectString,sizeof(sConnectString),&nOutLen,SQL_DRIVER_PROMPT); if(!SUCCEEDED(retval)) { ODBCError(hEnv); printf("SQLDriverConnect failed.\n"); goto exitproc; } else { sConnectString[nOutLen]='\0'; printf("Connected: %s\n",sConnectString); } retval=SQLAllocStmt(hDbc,&hStmt); if(!SUCCEEDED(retval) || !hStmt) { ODBCError(hEnv); printf("SQLAllocStmt failed.\n"); goto exitproc; } printf("Trying to execute SQLExecDirect(hStmt,\"\",SQL_NTS).\n"); __try { retval=SQLExecDirect(hStmt,(SQLCHAR*)"",SQL_NTS); }__except(HandleException(GetExceptionCode())) { ; } printf("Trying to execute SQLExecDirect(hStmt,\"\",0).\n"); __try { retval=SQLExecDirect(hStmt,(SQLCHAR*)"",0); }__except(HandleException(GetExceptionCode())) { ; } printf("Trying to execute SQLExecDirect(hStmt,\"SELECT * FROM tets\",SQL_NTS).\n"); __try { retval=SQLExecDirect(hStmt,(SQLCHAR*)"SELECT * FROM tets",SQL_NTS); }__except(HandleException(GetExceptionCode())) { ; } printf("Trying to execute SQLExecDirect(hStmt,\"SELECT * FROM tets\",18).\n"); __try { retval=SQLExecDirect(hStmt,(SQLCHAR*)"SELECT * FROM tets",18); }__except(HandleException(GetExceptionCode())) { ; } printf("Trying to execute SQLExecDirect(hStmt,\" \",SQL_NTS).\n"); __try { retval=SQLExecDirect(hStmt,(SQLCHAR*)" ",SQL_NTS); }__except(HandleException(GetExceptionCode())) { ; } printf("Trying to execute SQLExecDirect(hStmt,\" \",5).\n"); __try { retval=SQLExecDirect(hStmt,(SQLCHAR*)" ",5); }__except(HandleException(GetExceptionCode())) { ; } exitproc: if(hStmt) SQLFreeStmt(hStmt,SQL_DROP); if(hDbc) { if(fConnected) { SQLDisconnect(hDbc); } SQLFreeConnect(hDbc); } if(hEnv) SQLFreeEnv(hEnv); printf("Done, press any key to exit."); getchar(); }Here is the output for Advantage StreamlineSQL ODBC 3.00.00.06 Extended Systems, Inc:
Trying to connect ... Connected: DSN=.... Trying to execute SQLExecDirect(hStmt,"",SQL_NTS). Exception is thrown:0xC0000005 <---------------!!! Trying to execute SQLExecDirect(hStmt,"",0). Trying to execute SQLExecDirect(hStmt,"SELECT * FROM tets",SQL_NTS). Trying to execute SQLExecDirect(hStmt,"SELECT * FROM tets",18). Trying to execute SQLExecDirect(hStmt," ",SQL_NTS). Exception is thrown:0xC0000005 <---------------!!! Trying to execute SQLExecDirect(hStmt," ",5). Exception is thrown:0xC0000005 <---------------!!! Done, press any key to exit.Thanks,