Solved

Using DSN or DSN Less Connections for Database Connectivity

Posted on 2001-06-24
3
269 Views
Last Modified: 2010-05-02
Using DSN or DSN Less Connections for Database Connectivity in VB or ASP?

Can anyone give me a answer for the above?


Thank You

Anil Mahadev
0
Comment
Question by:ecomguru2000
3 Comments
 
LVL 15

Expert Comment

by:robbert
ID: 6222812
Mostly, DSN-less connections are used, basically, because they don't have to be set up.

Here are examples of DSN-less connection strings:
http://www.able-consulting.com/ADO_Conn.htm

If there are further questions let me know.
0
 
LVL 6

Accepted Solution

by:
kahlean earned 100 total points
ID: 6223069
DSN less connection are useful if your application is going to be on mutliple systems and the server information might change from location to location. By using a DSNless connection, you can store the data connection informatin in a file that is read each time the application start. If the information needs change, simply change the file information rather than distributing a new DSN. DSN-less connection are especially useful for web application because they allow you to move the application from one server to another without recreating the DSN on the server.


Here is a dsnless connection example.

'********************************************************

Public Function DSNless () AS Boolean

Dim cn AS New ADODB Connection
Dim sConn As String


On Error GoTo Err

DSNless = False

sConn = "Driver={Microsoft Access Driver (*.mdb)};" _
     & "DBQ=C:\dbName.mdb;" _
     & "UID=Admin;PWD='';"

cn.Open sConn
Debug.Print cn.ConnectionString
DSNless = True
Exit Function


Err
   MsgBox "Error in database connectivity"
   Exit Function
End Function

'******************************************************
On the other hand a DSN connection stores the information in a file that can be read by any application. THis make an application more easily portable between computer becauser only the file needs to be move rather than having an installation progam set ip a DSN on the target system. A DSN can be set via ODBC Data Source in your control panel. Here is a sample of a DSN connection

'********************************************************
Public Function DSNcon () AS Boolean

Dim cn AS New ADODB Connection

On Error GoTo Err

DSNcon = False

cn.Open "dsnDatabase"

Debug.Print cn.ConnectionString
DSNcon = True
Exit Function

Err
   MsgBox "Error in database connectivity"
   Exit Function

End Function

'*****************************************************





0
 
LVL 2

Expert Comment

by:TravisHall
ID: 6223202
Quoth kahlean, "DSN less connection are useful if your application is going to be on mutliple systems and the server information might change from location to location. By using a DSNless connection, you can store the data connection informatin in a file that is read each time the application start. If the information needs change, simply change the file information rather than distributing a new DSN."

Actually, if this is your concern, your best option is generally to use a File DSN, rather than going completely DSN-less. That way, you can still use the handy tools that create DSNs, and you have the advantage of having your app read what it needs from a file stored on your server.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question