By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

accessing MS Access database fila via ODBC problem

P: n/a
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

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Nov 13 '05 #2

P: n/a
I've solved it. Using SQLDriverConnect with the same DSN instead
SQLBrowseConnect solves this. But thanx!

David

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


Nov 13 '05 #3

P: n/a
"David Schofield" wrote
Maybe you need to post to another group,
this one is very VB-based,
No, this one is for any Microsoft Access related issue. That includes, but
is not limited to, the graphic UI, VBA code, SQL code, Query Builder,
Wizards....
but
1. Can't you use ADO instead of
ODBC? It is a lot easier.


I am not sure why you feel ADO is easier. I didn't find it so. I am more
comfortable using DAO and ODBC because I have been using it ever since
Access 2.0 was released in 1994, and DAO - Jet - ODBC - server is the
current recommendation of the Access team at Microsoft.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #4

P: n/a
On Tue, 12 Jul 2005 05:33:22 GMT, "Larry Linson"
<bo*****@localhost.not> wrote:
"David Schofield" wrote
Maybe you need to post to another group,
this one is very VB-based,


No, this one is for any Microsoft Access related issue. That includes, but
is not limited to, the graphic UI, VBA code, SQL code, Query Builder,
Wizards....
but
1. Can't you use ADO instead of
ODBC? It is a lot easier.


I am not sure why you feel ADO is easier. I didn't find it so. I am more
comfortable using DAO and ODBC because I have been using it ever since
Access 2.0 was released in 1994, and DAO - Jet - ODBC - server is the
current recommendation of the Access team at Microsoft.

Larry Linson
Microsoft Access MVP

Hi
I didn't mean it was off topic but just that he might get more replies
in another group, after all his is a C program and he hadn't been
answered here. By VB-based I meant the code discussed is usually vba.
On ODBC and Microsoft I am glad to hear it but it does sound like
backtracking to me. It isn't the impression given to the non Access
community.
Personally I have nearly always used DAO (and always in Access) but as
you know a few posters here are avid ADO converts.
Cheers
David

PS in 2002 someone asked here
Hi,
can you help to write a simple C code to send an sql query
to an access db?
thanx
alessio.

and michka replied
There is no simple C code since you need to do one of the following:
a) use COM to get to ADO/DAO to Jet, or
b) use the ODBC API to get to Jet
b) use OLE DB to get to Jet

(A) in C is insane, even in C++ its a challenge if you have not done
if before (and this is the wrong group for it).
(B) in C is beyond insane and difficult, and again this is the wrong
group for it.
(C) again requires C++ and COM, and once this is the wrong group for
it.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.