Question for the database gurus...

shekondar

Golden Member
Apr 10, 2003
1,119
0
0
I'm writing a program in Visual C++ 6.0 that retrieves data from an Access database and generates text files. The database opens fine, but when I open the database Windows shows a dialog prompting me to select a data source. This is the code I'm using to open the database:

CString str = "ODBC;DSN=MS Access Database;DBQ=";
str += filename_;
str += ";DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;";

db_.OpenEx(str); //db_ is a CDatabase

Is there any way to keep the dialog from popping up?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Yes. Code the database name into the CDatabase object.

If unsure how, use the class wizard to create a dummy CRecordset and then look at the functions generated.
 

Cerebus451

Golden Member
Nov 30, 2000
1,425
0
76
I've always created a DSN for my specific database, rather than supplying the file name at run time. That way I do a db_.OpenEx("DSN=MyDSNName"); and never get the prompt. My guess is that it cannot find the Access database that you are specifying?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Also, create an ODBC connection for the database. Removes all those parameters that you are feeding it.