connection with timesten database
570806Aug 16 2007 — edited Aug 16 2007hi everyone,
I have problem with connecting to timesten database can u help.
following is the code:
#ifdef WIN32
# include <windows.h>
#else
# include <sqlunix.h>
#endif
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
static void chkReturnCode(SQLRETURN rc, SQLHENV henv,
SQLHDBC hdbc, SQLHSTMT hstmt,
char* msg, char* filename,
int lineno, BOOL err_is_fatal);
#define DEFAULT_CONNSTR "DSN=scott_test_dsn;PermSize=32"
int main(int ac, char** av)
{
clrscr();
SQLRETURN rc = SQL_SUCCESS;
/* General return code for the API */
SQLHENV henv = SQL_NULL_HENV;
/* Environment handle */
SQLHDBC hdbc = SQL_NULL_HDBC;
/* Connection handle */
SQLHSTMT hstmt = SQL_NULL_HSTMT;
/* Statement handle */
SQLCHAR connOut[255];
/* Buffer for completed connection string */
SQLSMALLINT connOutLen;
/* number of bytes returned in ConnOut */
SQLCHAR connStr = (SQLCHAR)DEFAULT_CONNSTR;
/* Connection string */
rc = SQLAllocEnv(&henv);
if (rc != SQL_SUCCESS) {
fprintf(stderr, "Unable to allocate an "
"environment handle\n");
exit(1);
}
rc = SQLAllocConnect(henv, &hdbc);
chkReturnCode(rc, henv, SQL_NULL_HDBC,
SQL_NULL_HSTMT,
"Unable to allocate a "
"connection handle\n",
__FILE__, __LINE__, 1);
rc = SQLDriverConnect(hdbc, NULL,
connStr, SQL_NTS,
connOut, sizeof(connOut),
&connOutLen,
SQL_DRIVER_NOPROMPT);
chkReturnCode(rc, henv, hdbc, SQL_NULL_HSTMT,
"Error in connecting to the"
" data store\n",
__FILE__, __LINE__, 1);
rc = SQLAllocStmt(hdbc, &hstmt);
chkReturnCode(rc, henv, hdbc, SQL_NULL_HSTMT,
"Unable to allocate a "
"statement handle\n",
__FILE__, __LINE__, 1);
getch();
}
static void chkReturnCode(SQLRETURN rc, SQLHENV henv,SQLHDBC hdbc, SQLHSTMT hstmt,char* msg, char* filename,int lineno, BOOL err_is_fatal)
{
#define MSG_LNG 512
SQLCHAR sqlState[MSG_LNG];
/* SQL state string */
SQLINTEGER nativeErr;
/* Native error code */
SQLCHAR errMsg[MSG_LNG];
/* Error msg text buffer pointer */
SQLSMALLINT errMsgLen;
/* Error msg text Available bytes */
SQLRETURN ret = SQL_SUCCESS;
if (rc != SQL_SUCCESS &&
rc != SQL_NO_DATA_FOUND )
{
if (rc != SQL_SUCCESS_WITH_INFO)
{
/** It's not just a warning*/
fprintf(stderr, "*** ERROR in %s, line %d:"" %s\n",filename, lineno, msg);
}
/** Now see why the error/warning occurred*/
while (ret == SQL_SUCCESS ||ret == SQL_SUCCESS_WITH_INFO)
{
ret = SQLError(henv, hdbc, hstmt,
sqlState, &nativeErr,
errMsg, MSG_LNG,&errMsgLen);
switch (ret)
{
case SQL_SUCCESS:
fprintf(stderr, "*** %s\n""*** ODBC Error/Warning = %s, ""TimesTen Error/Warning "" = %d\n",
errMsg, sqlState,nativeErr);
break;
case SQL_SUCCESS_WITH_INFO:
fprintf(stderr," failed with return code of "
"SQL_SUCCESS_WITH_INFO.\n "
"*** Need to increase size of"
" message buffer.\n");
break;
case SQL_INVALID_HANDLE:
fprintf(stderr, "*** Call to SQLError"
" failed with return code of "
"SQL_INVALID_HANDLE.\n");
break;
case SQL_ERROR:
fprintf(stderr, "*** Call to SQLError"
" failed with return code of "
"SQL_ERROR.\n");
break;
case SQL_NO_DATA_FOUND:
break;
}
/* switch */
} /* while */
if (rc != SQL_SUCCESS_WITH_INFO && err_is_fatal)
{
fprintf(stderr, "Exiting.\n");
exit(-1);
}
}
}
m getting error in the functions:
SQLAllocEnv(...)
SQLAllocConnect(...)
SQLDriverConnect(..)
SQLAllocStmt(...)
as undefined symbol.
one more thing while compiling it shows no error but when running it shows linking error::Undefined Symbol
wtg for some response
Thanks
Pooja