DSN-Less Database Connections

 

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:mydatabasesorders.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:mydatabasestuffsystem.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

 

Microsoft Office VBA, MS Access 2003, 2007, 2010, 2013, 2016