f



accessing MS Access database fila via ODBC problem

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

0
dsiroky (7)
7/10/2005 10:55:30 AM
comp.databases.ms-access 42670 articles. 0 followers. Post Follow

4 Replies
2698 Views

Similar Articles

[PageSpeed] 21

On Sun, 10 Jul 2005 12:55:30 +0200, David Siroky <dsiroky@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

0
not
7/11/2005 8:22:02 AM
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 <dsiroky@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

0
dsiroky (7)
7/11/2005 1:10:07 PM
"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


0
bouncer (4168)
7/12/2005 5:33:22 AM
On Tue, 12 Jul 2005 05:33:22 GMT, "Larry Linson"
<bouncer@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. 
 

0
miles
7/12/2005 6:58:03 AM
Reply: