Is there an easy way to create a DSN-less connection to a database?
Steps to Create a DSN-Less Connection String for your Access and SQL Server database(s) using some nice windows features.
- Right-Click the desktop.
- Select New
- Select New Text File
- Give it a unique name
- Change the extension to "UDL" (Stands for Universal Data Link)
- Double-Click the file
- Walk through the wizard and test the connection.
- Click Finish to Save it to the file.
- Open the file in notepad.
- Copy the string that is written after the line 'Everything after this line is... etc'. This is your dsn-less connection to be used in your connection settings!
For Access databases you will need to remove the part of the physical drive location with where your database resides on our web server:
Example:
You have uploaded a database named "test.mdb" to a folder that hangs off the root of your account named "Database".
So you need to replace the file path with:
server.MapPath(".\database\test.mdb")
Comments
Spaces
A Very Useful FAQ..Thanks!!
Great FAQ..but the issue of spaces occurs with me also.
A minor niggle
DSN-Less Connection to Access
I tried under XP and also got the problem with the spaces. It also created a standard Microsoft Access connection. If you are using Access 2000 you will get better performace using a Jet 4.0 connection string like so:
<%
accessdb="mydata.mdb"
myDSN=myDSN & "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath(accessdb) & ";"
Dim oConn
Set oconn="server".createobject("adodb.connection")
oConn.open myDSN
If Err.Number = 0 Then
%>
Your code goes here
<%
Else 'Database connection failed so show a message
Response.Write "Database unavailable" & "<br>"
Response.Write "Err Number: " & Err.Number & "<br>"
Response.Write "Description: " & Err.Description & "<br>"
End If
oConn.close
set oConn = nothing
%>
You must me logged in to write a comment.