Click to See Complete Forum and Search --> : How to get DSN less connections


sriky
January 13th, 2000, 02:51 PM
I am using ADO's to connect to Access database. I assume in that case, it runs without DSN at the client site.

Thanks

Johnny101
January 13th, 2000, 03:10 PM
You don't have to use a DSN-less connection with ADO just because you're using an Access database. Although, it would be better not to use one (less hassle to set up app on new machine). To use a DSN-less connection with ado and an Access database, the following should work:


Dim cn as ADODB.Connection
Dim rs as ADODB.Recordset

set cn = new ADODB.Connection
cn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};"
cn.ConnectionString = cn.ConnectionString & "DBQ=" & App.Path & "\accessfile.mdb;"

cn.Open





You will of course have to provide the correct path to the .mdb file after the 'DQB' switch.

This should get you going.

Good luck.

John


John Pirkey
MCSD
www.ShallowWaterSystems.com

January 17th, 2000, 02:31 PM
what is the difference between DSN connection and DSNless connection?
Explain

Johnny101
January 17th, 2000, 03:17 PM
DSN stands for DataSource Name. These are setup in the control panel under ODBC32. There are system DSNs and user DSNs on a machine. To use a DSN in your connectionstring you would specify the DSN, UID and PWD instead of the above way. Connecting to a database with a DSN uses the ODBC protocol, without - uses the OLE DB protocol (when used with ADO). To use a DSN with an Access database, you add a new entry in the ODBC section of the control and point it to an Access database. You can name this "pointer" anything you want. For example, I have an .mdb in my C:\dev\vb directory that i want to connect to. I could add a DSN for this database, call it MyDSN and use it in a connection string like this:

cn.connectionstring = "DSN=MyDSN;UID=admin;PWD=;"
cn.open

If the DSN is set up correctly, the connection will be opened.

One of the bad things about using DSN's in production apps, is every machine that will use your app will have to have a DSN setup on that local machine. This leads to the nice thing about not using DSNs, you can move your app anywhere and as long as your code is supplying the path to the .mdb relatively (ie. app.path & "..\..\path\path2\filename.mdb") it will run.

Hope this helps,
John

John Pirkey
MCSD
www.ShallowWaterSystems.com