Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to connect MSAccess using connection string

Status
Not open for further replies.

alexisdumb

Programmer
May 21, 2002
8
AU
in a simple MFC db app created by the wizard, how does one connect to a MSAccess database using a connection string instead of a DSN?
basically, i jsut want to distribute an app without the user having to setup their own DSN and without creating a DSN on their machine. is this possible?
and would the user be required to have a ODBC driver already installed on their machine??

thanks
alex
 
figured this much out...

using a DSN for an app that we might want to distribute
to end users just didn't seem right. we would have to
get the user to set the DSN up or programmitically set
one up in our code. there had to be a better way.

after searching the past few hours, the best solution i
found so far was to not put anything down as a DSN.
ie in the RecordSet class, the GetDefaultConnection
method, remove the name of your DSN.
this compiles and when run, asks for you to select a
DSN or create one.

pretty lame!

i gave up trying to find how to setup a connection
string and after alot of playing and fiddling, set up
a "File DSN". seemed an OK solution, but still not good
enough!

ANYWAY.... came up with this (replace
GetDefaultConnection in the RecordSet class to...


CString CDbSet::GetDefaultConnect()
{
CString connString;

connString = "ODBC;DRIVER=Microsoft Access Driver *.mdb);" +
connString += "UID=admin;";
connString += "UserCommitSync=no;";
connString += "Threads=3;";
connString += "SafeTransactions=0;";
connString += "PageTimeout=5;";
connString += "MaxScanRows=8;";
connString += "MaxBufferSize=2048;";
connString += "FIL=MS Access;";
connString += "DriverId=25;";
connString += "DBQ=alex.mdb;";

return connString;

}


this is basically just the contents of the file DSN,
but removed the absolute path at DBQ=.... and the
DEFAULTLOCATION
seems to be working great! jsut wondering now how users
who don't have access setup on their machines would use
such an app? is there a way to setup a ODBC driver on
their machine? is this legal and/or ethical? is it
required?

note also, that if running in debug mode, the db needs
to be in the folder ABOVE Debug folder for the relative
path to work, otherwise use \ to escape folders
ie c:\\windows\\mydbs\\mydb.mdb

good luck!
alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top