Home  Fees/Services  Access Examples  Programming Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Website to Database Connections
DSN Less Database Connection Example

DSN-Less Connection String Database Connection Methods

 Microsoft Access Tutorials>DB Connection>DSN-Less Connection



Connect to Access DSN

Connect to OLEDB Provider for Jet

Connect to Remote Database

ADO File-DSN Database Connection

DSN-Less Connection String

SQL/Server ODBC Database Connection Method

OLE DB UDL Database Connection

Connection Open Method Defined


DSN-less Connection String Code

DSN less Connection Method Example

DSN less database connection string example is shown in the first example below and can be used with Microsoft Access databases and others.  DSN less method is considered to be faster than the DSN method.

Dim conn as DB.Connection
Dim rst as DB.Recordset
Dim sql as string
'---------------

Without workgroup security, .mdw system file:
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
                   "DBQ=path_to_database;" & _
                   "PWD=password;"

With workgroup security:
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
                   "DBQ=path_to_database;" & _
                   "SystemDB=path_to_system_database;" & _
                   "PWD=password;"

Where:
path_to_database = The database path, such as F:\mydatabases\orders.mdb

username = the username you have identified in the database, or the default 'Admin' username.

password = the password you have setup in the database or nothing  "Pwd=;" for no password.

path_to_system_database the path to where the system MDW file exits, such as X:\mydatabasestuff\system.mdw

'--------------  here we use the dsn-less connection

sql = "select sales_rep, dollars from sales_by_rep_chart"

Set rst = Server.CreateObject(" DB.Recordset")
rst.Open sql, conn, 3, 3
Set Session("mysession") = rst
rst.movefirst
response.write rst!sales_rep

'--------------

Where mysession is any name for the session.

When done with the recordset don't forget to close it:

Conn.close
set conn=nothing

You may also disconnect from the DSN-less database connections session by issuing:

session.abandom



Contact Information

Microsoft Access Developers
Microsoft Access 2003 2000 2002(XP) 97 All Windows Versions