15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Selecting files using ODBC

Allan Rentcome -- rentcome@ix.netcom.com
Wednesday, January 29, 1997

Environment: MSVC 4.1 Win95

Hi,

My application uses ODBC and a data source for accessing Access database
files. During the initial installation of my application I configure for
the user a default data source, but the user still needs to select the
specific Access Database to associate with the data source. I can use the
ODBC dialog box to allow the user to select the database to associate with
the data source, but I would like the user to be able to select the data
file from within my application.

Can someone help in explaining the procedure or best way to allow a user to
simply select a database from a standard file dialog box and then open that
file for use within the application. I know I can do this using DAO, but I
have other reasons for using ODBC. In other words, once I have configured a
data source using the MDB driver how can I programmatically associate a
specific Access file to the data source?

Many thanks for any help

Allan



P.J. Tezza -- pj@exemplarsoftware.com
Thursday, January 30, 1997

[Mini-digest: 7 responses]

Dear Allan,

Before calling any ODBC functions, display your own dialogs (maybe, say, a 
CFileDialog which looks for *.mdb files) to get the path to the database 
file your user wishes to open and his user name and password (username and 
password are optional). Then call SQL driver connect, feeding it the 
appropriate connect string. If your setup application is creating the 
"standard" MS Access Databases data source (which it probably should), a 
connect string like the following will work:
"DSN=MS Access Databases;DBQ=%db;UID=%uid;PWD=%pwd;FIL=RedISAM"
Where %db is the full path to the database file, %uid is the user name and 
%pwd is the password.

If you use and NULL hwnd and the SQL_DRIVER_NOPROMPT flag with 
SQLDriverConnect, you can be sure that ODBC will not display any 
disconcerting dialogs.

This same procedure works for other ODBC drivers like the Excel and Text 
drivers, but the connect strings are different. It is theoretically 
possible to query the driver for the connect string syntax and parameters, 
but for the standard ODBC Desktop drivers, this is overkill.

PJ


----------
From: 	Allan Rentcome[SMTP:rentcome@ix.netcom.com]
Sent: 	Wednesday, January 29, 1997 5:42 AM
To: 	mfc-l@netcom.com
Subject: 	Selecting files using ODBC

Environment: MSVC 4.1 Win95

Hi,

My application uses ODBC and a data source for accessing Access database
files. During the initial installation of my application I configure for
the user a default data source, but the user still needs to select the
specific Access Database to associate with the data source. I can use the
ODBC dialog box to allow the user to select the database to associate with
the data source, but I would like the user to be able to select the data
file from within my application.

Can someone help in explaining the procedure or best way to allow a user to
simply select a database from a standard file dialog box and then open that
file for use within the application. I know I can do this using DAO, but I
have other reasons for using ODBC. In other words, once I have configured a
data source using the MDB driver how can I programmatically associate a
specific Access file to the data source?

Many thanks for any help

Allan

-----From: jeremy.farr@bandw.co.uk

In your connect string - after "ODBC;DSN=3DAccess 2.0 databases;" or whatev=
er
add "DBQ=3DC:\\Data.mdb;" or suchlike  [remember the double backslashes]

HTH
Jerry Farr
 ----------
To:  -:  @ UUCP,  jeremy farr @ bwuk =20
cc: =20
From:  MIME:rentcome @ ix.netcom.com  @ UUCP
Date: 31/01/97 02:55:37
Subject: Selecting files using ODBC=20

Environment: MSVC 4.1 Win95

Hi,

My application uses ODBC and a data source for accessing Access database
files. During the initial installation of my application I configure for
the user a default data source, but the user still needs to select the
specific Access Database to associate with the data source. I can use the
ODBC dialog box to allow the user to select the database to associate with
the data source, but I would like the user to be able to select the data
file from within my application.

Can someone help in explaining the procedure or best way to allow a user to
simply select a database from a standard file dialog box and then open that
file for use within the application. I know I can do this using DAO, but I
have other reasons for using ODBC. In other words, once I have configured a
data source using the MDB driver how can I programmatically associate a
specific Access file to the data source?

Many thanks for any help

Allan
-----From: jeremy.farr@bandw.co.uk

In your connect string - after "ODBC;DSN=3DAccess 2.0 databases;" or whatev=
er
add "DBQ=3DC:\\Data.mdb;" or suchlike

Jerry Farr
 ----------
To:  -:  @ UUCP,  jeremy farr @ bwuk =20
cc: =20
From:  MIME:rentcome @ ix.netcom.com  @ UUCP
Date: 31/01/97 02:55:37
Subject: Selecting files using ODBC=20

Environment: MSVC 4.1 Win95

Hi,

My application uses ODBC and a data source for accessing Access database
files. During the initial installation of my application I configure for
the user a default data source, but the user still needs to select the
specific Access Database to associate with the data source. I can use the
ODBC dialog box to allow the user to select the database to associate with
the data source, but I would like the user to be able to select the data
file from within my application.

Can someone help in explaining the procedure or best way to allow a user to
simply select a database from a standard file dialog box and then open that
file for use within the application. I know I can do this using DAO, but I
have other reasons for using ODBC. In other words, once I have configured a
data source using the MDB driver how can I programmatically associate a
specific Access file to the data source?

Many thanks for any help

Allan

=20

-----From: ybriklin@juno.com (Yuriy Briklin)

Hi  Allan.

After you prompt a user for a database file name (using File Open dialog
if you want) you
should update ODBC.INI in user's windows directory.  Take a look into
this file for the information you have to supply.

Yuriy Briklin
e-mail: ybriklin@juno.com


On Wed, 29 Jan 1997 04:42:49 -0600 "Allan Rentcome"
 writes:
> Environment: MSVC 4.1 Win95
> 
> Hi,
> 
> My application uses ODBC and a data source for accessing Access 
> database
> files. During the initial installation of my application I configure 
> for
> the user a default data source, but the user still needs to select 
> the
> specific Access Database to associate with the data source. I can use 
> the
> ODBC dialog box to allow the user to select the database to associate 
> with
> the data source, but I would like the user to be able to select the 
> data
> file from within my application.
> 
> Can someone help in explaining the procedure or best way to allow a 
> user to
> simply select a database from a standard file dialog box and then 
> open that
> file for use within the application. I know I can do this using DAO, 
> but I
> have other reasons for using ODBC. In other words, once I have 
> configured a
> data source using the MDB driver how can I programmatically associate 
> a
> specific Access file to the data source?
> 
> Many thanks for any help
> 
> Allan
> 
-----From: barley@rdaconsultants.com (Ray Barley)

You can use the function SQLConfigDataSource() in the ODBC installer DLL
to add, modify, or delete a data source.  Remember to #include
.  In my case, I've only used it to create data sources.  If
the data source name already exists it just overwrites it.

>----------
>From: 	Allan Rentcome[SMTP:rentcome@ix.netcom.com]
>Sent: 	Wednesday, January 29, 1997 5:42 AM
>To: 	mfc-l@netcom.com
>Subject: 	Selecting files using ODBC
>
>Environment: MSVC 4.1 Win95
>
>Hi,
>
>My application uses ODBC and a data source for accessing Access database
>files. During the initial installation of my application I configure for
>the user a default data source, but the user still needs to select the
>specific Access Database to associate with the data source. I can use the
>ODBC dialog box to allow the user to select the database to associate with
>the data source, but I would like the user to be able to select the data
>file from within my application.
>
>Can someone help in explaining the procedure or best way to allow a user to
>simply select a database from a standard file dialog box and then open that
>file for use within the application. I know I can do this using DAO, but I
>have other reasons for using ODBC. In other words, once I have configured a
>data source using the MDB driver how can I programmatically associate a
>specific Access file to the data source?
>
>Many thanks for any help
>
>Allan
>
-----From: Mihir Dalal 



On Wed, 29 Jan 1997, Allan Rentcome wrote:

> Environment: MSVC 4.1 Win95
> 
> Hi,
> 
> My application uses ODBC and a data source for accessing Access database
> files. During the initial installation of my application I configure for
> the user a default data source, but the user still needs to select the
> specific Access Database to associate with the data source. I can use the
> ODBC dialog box to allow the user to select the database to associate with
> the data source, but I would like the user to be able to select the data
> file from within my application.
> 
> Can someone help in explaining the procedure or best way to allow a user to
> simply select a database from a standard file dialog box and then open that
> file for use within the application. I know I can do this using DAO, but I
> have other reasons for using ODBC. In other words, once I have configured a
> data source using the MDB driver how can I programmatically associate a
> specific Access file to the data source?
> 
> Many thanks for any help
> 
> Allan

Allan, 

I have implemented exactly the same as what you intend to, but for dbase 
III files.

What you need to do basically, is to completely scrap your App Wizard 
generated serialization code (incase, you application deals with database 
files ONLY) and override most of the file related functions in your 
CYourDoc/CYourApp class.

In your overrides, you will use the ODBC API to open/manipulate/close 
database tables/files. Things get a bit tricky and complicated since, the 
ODBC API is not designed to handle this kind of an operation, and I 
believe, has lot of limitations. 

Hope that helps.

Feel free to reach me again if you need specfic code illustrations. 

Mihir. 

___________________________________________________________________________
    Mihir Dalal , M.Engg. (Electrical) Student
             Department of Electrical and Computer Engineering
                  Concordia University, Montreal, Canada
              http://www.ECE.Concordia.CA/~m_dalal/addr.html

-----From: "Jerry Farr" 

GetDefaultConnect:

return "ODBC;DSN=Access 2.0 Databases;DBQ=C:\Path\Data.mdb;";

HTH
J
----------
> From: Allan Rentcome 
> To: mfc-l@netcom.com
> Subject: Selecting files using ODBC
> Date: 29 January 1997 10:42
> 
> Environment: MSVC 4.1 Win95
> 
> Hi,
> 
> My application uses ODBC and a data source for accessing Access database
> files. During the initial installation of my application I configure for
> the user a default data source, but the user still needs to select the
> specific Access Database to associate with the data source. I can use the
> ODBC dialog box to allow the user to select the database to associate
with
> the data source, but I would like the user to be able to select the data
> file from within my application.
> 
> Can someone help in explaining the procedure or best way to allow a user
to
> simply select a database from a standard file dialog box and then open
that
> file for use within the application. I know I can do this using DAO, but
I
> have other reasons for using ODBC. In other words, once I have configured
a
> data source using the MDB driver how can I programmatically associate a
> specific Access file to the data source?
> 
> Many thanks for any help
> 
> Allan



Mihir Dalal -- m_dalal@ECE.concordia.CA
Saturday, March 29, 1997

On Wed, 29 Jan 1997, Allan Rentcome wrote:

> Environment: MSVC 4.1 Win95
> 
> Hi,
> 
> My application uses ODBC and a data source for accessing Access database
> files. During the initial installation of my application I configure for
> the user a default data source, but the user still needs to select the
> specific Access Database to associate with the data source. I can use the
> ODBC dialog box to allow the user to select the database to associate with
> the data source, but I would like the user to be able to select the data
> file from within my application.
> 
> Can someone help in explaining the procedure or best way to allow a user to
> simply select a database from a standard file dialog box and then open that
> file for use within the application. I know I can do this using DAO, but I
> have other reasons for using ODBC. In other words, once I have configured a
> data source using the MDB driver how can I programmatically associate a
> specific Access file to the data source?
> 
> Many thanks for any help
> 
> Allan

For that, you will have to use WritePrivateProfileString() API to write 
into the "odbc.ini" file. 

Check the format of your data source section in your system odbc.ini 
file. That should give you more ideas. 

Mihir. 

 _________________________________________________________________________
     Mihir Dalal , M.Engg. (Electrical) Student
              Department of Electrical and Computer Engineering
                   Concordia University, Montreal, Canada
                http://www.ECE.Concordia.CA/~m_dalal/addr.html





Become an MFC-L member | Вернуться в корень Архива |