473,772 Members | 3,665 Online
Bytes | Software Development & Data Engineering Community
+ 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={Micros oft Access Driver (*.mdb)};DBQ=c: \\dev-cpp\\test\\1.md b";

SQLAllocEnv(&en v);
SQLAllocConnect (env, &hdbc);
SQLBrowseConnec t(hdbc,
(UCHAR*)DSN,
strlen(DSN),
(UCHAR*)buf,
BUF_SIZE,
(SQLSMALLINT*)& rcvlen);

The function SQLBrowseConnec t fails and SQLGetDiagRec returns
"IM001 Driver does not support this function"

Can anyone help me?

Thanks!

David

Nov 13 '05 #1
4 2747
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={Micros oft Access Driver (*.mdb)};DBQ=c: \\dev-cpp\\test\\1.md b";

SQLAllocEnv(&e nv);
SQLAllocConnec t(env, &hdbc);
SQLBrowseConne ct(hdbc,
(UCHAR*)DSN,
strlen(DSN),
(UCHAR*)buf,
BUF_SIZE,
(SQLSMALLINT*)& rcvlen);

The function SQLBrowseConnec t 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(h env, SQL_ATTR_ODBC_V ERSION,
(void*)SQL_OV_O DBC3, 0);
ENV_HANDLE_CHEC K( henv, retcode ) //returns nonzero if error

/* Allocate connection handle */
retcode = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc);
ENV_HANDLE_CHEC K( henv, retcode ) //returns nonzero if error

/* Set login timeout to 5 seconds. */
/* SQLSetConnectAt tr(hdbc, (void*)SQL_LOGI N_TIMEOUT, 5, 0); */

/* Connect to data source */
retcode = SQLConnect(hdbc , (SQLCHAR*) "MTM", SQL_NTS,
(SQLCHAR*) "db2admin", SQL_NTS,
(SQLCHAR*) "db2admin", SQL_NTS);
DBC_HANDLE_CHEC K( hdbc, retcode ) //returns nonzero if error

David

Nov 13 '05 #2
I've solved it. Using SQLDriverConnec t with the same DSN instead
SQLBrowseConnec t 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={Micros oft Access Driver (*.mdb)};DBQ=c: \\dev-cpp\\test\\1.md b";

SQLAllocEnv(& env);
SQLAllocConne ct(env, &hdbc);
SQLBrowseConn ect(hdbc,
(UCHAR*)DSN,
strlen(DSN),
(UCHAR*)buf,
BUF_SIZE,
(SQLSMALLINT*)& rcvlen);

The function SQLBrowseConnec t 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(h env, SQL_ATTR_ODBC_V ERSION,
(void*)SQL_OV_O DBC3, 0);
ENV_HANDLE_CHEC K( henv, retcode ) //returns nonzero if error

/* Allocate connection handle */
retcode = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc);
ENV_HANDLE_CHEC K( henv, retcode ) //returns nonzero if error

/* Set login timeout to 5 seconds. */
/* SQLSetConnectAt tr(hdbc, (void*)SQL_LOGI N_TIMEOUT, 5, 0); */

/* Connect to data source */
retcode = SQLConnect(hdbc , (SQLCHAR*) "MTM", SQL_NTS,
(SQLCHAR*) "db2admin", SQL_NTS,
(SQLCHAR*) "db2admin", SQL_NTS);
DBC_HANDLE_CHEC K( 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*****@localh ost.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
3764
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 2003 Server or ADO or ODBC issue, I am posting this on all of the three newsgroups. That's the setup: Windows 2003 Server with IIS and ASP.NET actiavted Access 2002 mdb file (and yes, proper rights are set on TMP paths and path,
3
2570
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 datasource. I create the linked tables without any problems, clicking on "save password" before selecting the desired tables. I can then access both tables fine from within the Access GUI.
49
14356
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 application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
0
2060
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 running that application after installing all required updates (Windows, Office, ..) It did work before updating, with a basic OS + application installation. Somewhere an update dit break things, but we do not know which one.
3
7903
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 object Set db = Server.CreateObject("ADODB.Connection") 'specify the database provider
6
13999
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 and error 'Object reference not set to an instance of an object.' as soon as I try to access the data in the fields, I.e. at the line that reads 'KeyFlags(i) = rstFields("keyflag").value'
1
1491
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
2287
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 details. I can map the network drive by providing username, but I can't use the odbc to access the info. Any ideas? I set up security to make sure that I can access it.
1
3725
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 close to mine, but nothing has helped. We are running Apache/2.2.4 (Win32) PHP/5.2.3. I am trying to use the odbc_connect to connect to an MS Access database that is on another server. I have tried to use both a system DSN, as well as putting the...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.