int main()
{
HENV hEnv = NULL;
HDBC hdbc = NULL;
SQLRETURN rc;
SQLRETURN rc2;
SQLCHAR SqlState[6], SQLStmt[100], Msg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER NativeError;
SQLSMALLINT MsgLen;
printf("Hello ODBC Program");
// Allocate Environment Handle
rc = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&hEnv);
if((rc != SQL_SUCCESS) && (rc!=SQL_SUCCESS_WITH_INFO))
{
SQLFreeHandle(SQL_HANDLE_ENV,hEnv);
exit(255);
}
rc = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
if((rc != SQL_SUCCESS) && (rc!=SQL_SUCCESS_WITH_INFO))
{
SQLFreeHandle(SQL_HANDLE_ENV,hEnv);
exit(255);
}
// Allocate Connection Handle
rc = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hdbc);
if((rc != SQL_SUCCESS) && (rc!=SQL_SUCCESS_WITH_INFO))
{
if( (rc2 = SQLGetDiagRec(SQL_HANDLE_ENV, hEnv, 1, SqlState, &NativeError,
Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA)
printf("\n Error %s SQLSTATE: %s, NativeError: %d",Msg,SqlState,NativeError);
SQLFreeHandle(SQL_HANDLE_ENV,hEnv);
exit(255);
}
return(0);
}
I got the above "[Microsoft][ODBC Driver Manager] Function sequence error SQLSTATE: HY010" error when I tried to create connection handle.When I set the environment attribute SQL_ATTR_ODBC_VERSION to ODBC3.0
No comments:
Post a Comment