473,471 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Nov 13 '05 #1
4 2721
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
3
by: James Bird | last post by:
Hello In order to perform a hetrogeneous join (I think that's what they're called) between MySQL and another database, I've created an Access database containing linked tables from each...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
0
by: vginders | last post by:
Hello, We have a legacy application which relies on an Access 97 database (upgrading is nog an option atm). As we are setting up a new server (Windows 2003), we started experiencing problems...
3
by: Russell Read [MSFT] | last post by:
Hi all, I am using VB script in ASP to access a MS Access database. This works fine until I want to access the same db placed on a file share. The code I am using is... 'create connection...
6
by: Andy Barber | last post by:
Hi, I'm trying to write an app that reads data from a table into a string variable for later use in my program. Below is a snippet of the code I'm using, which compiles ok, but at runtime I get...
1
by: timasmith | last post by:
Hi, If I have a computer without Microsoft Access installed but with an ODBC connection to a .mdb file - can I still access the 'database' via ODBC? thanks Tim
9
by: kilquonk | last post by:
We have an asp script on an NT system that is trying to access a database on an XP server. When it gets to setting up odbc, it gives an error on that line in a particular function but doesn't give...
1
by: vbace2 | last post by:
I have searched this forum, and the web, and I have not been able to find a solution to my issue. I may not have used the right search information to find the answer, but I found a lot of issues...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.