Tom Carlson
August 30th, 1999, 06:38 PM
I am attempting to connect to a DB2 database from inside an NT service:
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1= SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
RETCODE retcode;
UCHAR szDSN[ SQL_MAX_DSN_LENGTH +1 ] ="DATASOURCE",
szUID[ 31 ] = "USERID",
szAuthStr[ 31 ] = "USERPW";
retcode = SQLAllocHandle( SQL_HANDLE_ENV, NULL, &m_hEnv );
retcode = SQLSetEnvAttr( m_hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC2, SQL_IS_POINTER );
retcode = SQLAllocHandle( SQL_HANDLE_DBC, m_hEnv, &hdbc1 );
retcode = SQLConnect( hdbc1, szDSN, (SWORD)strlen( (const char*)szDSN ), szUID, (SWORD)strlen( (const char*)szUID ),szAuthStr, (SWORD)strlen( (const char*)szAuthStr));
if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ){
SQLCHAR buffer[ 255 ], buffer2[ 255 ];
SHORT len, len2;
TCHAR szState[ SQL_MAX_MESSAGE_LENGTH ];
TCHAR szErrorMsg[ SQL_MAX_MESSAGE_LENGTH ];
SDWORD pfNativeError;
SHORT pcbErrorMsg;
SQLError( m_hEnv, hdbc1,SQL_NULL_HSTMT, (SQLCHAR*)szState, &pfNativeError, (SQLCHAR*)szErrorMsg,SQL_MAX_MESSAGE_LENGTH -1, &pcbErrorMsg );
}
return 0;
This code works fine in an .exe, but when run inside a service, I receive COMM Link errors.
I suspect there might be a security issue, but I haven't been able to figure it out.
Any help would be appreciated!
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc1= SQL_NULL_HDBC;
SQLHSTMT hstmt1 = SQL_NULL_HSTMT;
RETCODE retcode;
UCHAR szDSN[ SQL_MAX_DSN_LENGTH +1 ] ="DATASOURCE",
szUID[ 31 ] = "USERID",
szAuthStr[ 31 ] = "USERPW";
retcode = SQLAllocHandle( SQL_HANDLE_ENV, NULL, &m_hEnv );
retcode = SQLSetEnvAttr( m_hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC2, SQL_IS_POINTER );
retcode = SQLAllocHandle( SQL_HANDLE_DBC, m_hEnv, &hdbc1 );
retcode = SQLConnect( hdbc1, szDSN, (SWORD)strlen( (const char*)szDSN ), szUID, (SWORD)strlen( (const char*)szUID ),szAuthStr, (SWORD)strlen( (const char*)szAuthStr));
if( retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO ){
SQLCHAR buffer[ 255 ], buffer2[ 255 ];
SHORT len, len2;
TCHAR szState[ SQL_MAX_MESSAGE_LENGTH ];
TCHAR szErrorMsg[ SQL_MAX_MESSAGE_LENGTH ];
SDWORD pfNativeError;
SHORT pcbErrorMsg;
SQLError( m_hEnv, hdbc1,SQL_NULL_HSTMT, (SQLCHAR*)szState, &pfNativeError, (SQLCHAR*)szErrorMsg,SQL_MAX_MESSAGE_LENGTH -1, &pcbErrorMsg );
}
return 0;
This code works fine in an .exe, but when run inside a service, I receive COMM Link errors.
I suspect there might be a security issue, but I haven't been able to figure it out.
Any help would be appreciated!