On Sun, 10 Jul 2005 12:55:30 +0200, David Siroky <ds*****@email.cz>
wrote:
Hi!
I'm trying to connect to a MDB file via ODBC like this:
char *DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dev-cpp\\test\\1.mdb";
SQLAllocEnv(&env);
SQLAllocConnect(env, &hdbc);
SQLBrowseConnect(hdbc,
(UCHAR*)DSN,
strlen(DSN),
(UCHAR*)buf,
BUF_SIZE,
(SQLSMALLINT*)&rcvlen);
The function SQLBrowseConnect fails and SQLGetDiagRec returns
"IM001 Driver does not support this function"
Can anyone help me?
Thanks!
David
Hi
Maybe you need to post to another group, this one is very VB-based,
but
1. Can't you use ADO instead of ODBC? It is a lot easier.
2. Last time I did this sort of thing I set up a system DSN in
advance ("MTM" in the example below) and connected to it as follows.
(This was db2 but Access should be similar).
/* allocate an environment handle */
retcode = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv )
;
if ( retcode != SQL_SUCCESS )
{ printf( "\n--ERROR while allocating the environment handle.\n"
) ;
printf( " retcode = %d\n", retcode);
printf( " line = %d\n", __LINE__);
printf( " file = %s\n", __FILE__);
return( 1 ) ;
}
/* Set the ODBC version environment attribute */
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(void*)SQL_OV_ODBC3, 0);
ENV_HANDLE_CHECK( henv, retcode ) //returns nonzero if error
/* Allocate connection handle */
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
ENV_HANDLE_CHECK( henv, retcode ) //returns nonzero if error
/* Set login timeout to 5 seconds. */
/* SQLSetConnectAttr(hdbc, (void*)SQL_LOGIN_TIMEOUT, 5, 0); */
/* Connect to data source */
retcode = SQLConnect(hdbc, (SQLCHAR*) "MTM", SQL_NTS,
(SQLCHAR*) "db2admin", SQL_NTS,
(SQLCHAR*) "db2admin", SQL_NTS);
DBC_HANDLE_CHECK( hdbc, retcode ) //returns nonzero if error
David