ASP Hosting Top Header
Easy ASP Hosting Logo ASP.NET Hosting   Toll Free: (800) 579-1657
ASP Hosting Contact Information
Windows Hosting
         Home         Hosting         Domains         Support          Order Windows 2003 Hosting
Helm Hosting
  DSN vs DSN less Database Connections

Introduction
In this article we will learn the two ways of connecting to database :

  • via DSN ( Data Source Name )
  • without DSN

DSN Connections
DSN stands for 'Data Source Name'. It is an easy way to assign useful and easily rememberable names to data sources which may not be limited to databases alone e.g Excel spread sheet etc.

Once you are done creating a DSN for your data source ( MS Access database lets say ), you can connect to it using following code :

<%
Dim con
Set con = Server.CreateObject("ADODB.Connection")

con.Open "DSN=mydsn"

' Now database is open and we are connected
' Do some thing here
'We are done so lets close the connection

con.Close
Set con = Nothing
%>


Explanation
The only significant point to see is that we have used "DSN=mydsn" to connect to our database using our DSN which in this case is mydsn.


DSN less Connection

DSN less connections don't require creation of system level DSNs for connecting to databases and provide an alternative to DSNs. We will now see how to connect to a database via ASP using Connection String in place of DSN name.

<%
Dim con
Set con = Server.CreateObject("ADODB.Connection")

con.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data" & _
"Source=c:\domains\yourdomain.com\db\yourdatabase.mdb"

' Now database is open and we are connected
' Do some thing here
'We are done so lets close the connection

con.Close
Set con = Nothing
%>


Explanation
The only change is use of a Connection String in place of a rather easy to remember DSN. Above code connects to an imaginary Access database. Connection Strings for other databases are different.

How to construct a Connection String for Access Databases ?

For Access database :-
With native OLE DB Provider ( preferred ):
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\domains\yourdomain.com\db\yourdatabase.mdb

Using ODBC connection without specifying a DSN :
Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\domains\yourdomain.com\db\yourdatabase.mdb


Note, always use the first Connection String that uses native OLE DB provider because it is faster than the second one. 'Data Source' or 'DBQ' are absolute path to the database.


Why to use DSN Connections ?

1) Provides easy to remember data source names.
2) When there are lots of data sources to think of and you want a central repository to hold the collection of data sources without having to worry about the actual site and configuration of the data sources.


Why to use DSN less Connections ?

1) When you can't register DSNs yourself e.g. when you are running a virtual hosting account on other's server. Stop emailing system administerator, connect to your databases directly.
2) Provides faster database access because it uses native OLE DB providers, while DSN connections make use of ODBC drivers.

 

Home |  Hosting |  Resellers |  About Us |  Testimonials |  Site Map |  Contact Us |  Data Center |  Helm |  Support |  Announcements |  Order