Back to Top
The nuts and bolts for
Creative web development

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.

  1. Right-Click the desktop.
  2. Select New
  3. Select New Text File
  4. Give it a unique name
  5. Change the extension to "UDL" (Stands for Universal Data Link)
  6. Double-Click the file
  7. Walk through the wizard and test the connection.
  8. Click Finish to Save it to the file.
  9. Open the file in notepad.
  10. 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")

Marcellino Bommezijn

Marcellino BommezijnMarcellino Bommezijn is one of the managers at dmxzone.com. He is a contributor on the tutorials section.

Owner of Senzes Media (http://www.activecontent.nl) which provides professional services and web applications for mid-sized companies.

ActiveContent CMS is the ASP.NET Content Management solution that is used for building professional and rich-featured websites.

See All Postings From Marcellino Bommezijn >>

Share this Article

Comments

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
%>

 

A Very Useful FAQ..Thanks!!

Great FAQ..but the issue of spaces occurs with me also.

A minor niggle

Spaces

On every machine I have tried this on, the resultant string when opened in notepad comes with spaces inbetween each letter, its not a huge point but is there any way to get rid of the spaces??