Solved

Using DSN or DSN Less Connections for Database Connectivity

Posted on 2001-06-24
3
273 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
to transfer string from C lanaguage to VBA 4 78
VBA/SQL - Connect to SQL server and pull data 4 137
RUNRMTCMD from AS/400 13 101
Set WorkSheet  not Working 9 52
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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