?
Solved

Using DSN or DSN Less Connections for Database Connectivity

Posted on 2001-06-24
3
Medium Priority
?
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

801 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