how can i create a DSN in runtime

Posted on 2003-10-28
Last Modified: 2010-05-01
i'm work win a access 2000 db, and  i just want to create the DSN with code, but before use de code i want con ask if the DSN exist, if the code exist i just use it, if it don't exist i create it  

i'm developing an aplication that use Crytal Report 8.5, it suppouse that the user can install this aplication in any folder; therefore the aplication should detect the data sources that will use the crytal report
Question by:darknighter
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
  • 3
  • 2
  • +2

Accepted Solution

_ys_ earned 125 total points
ID: 9634203
Check under the registry key
for the dsn you're expecting to see - it'll be a string value - the value will be "Microsoft Access Driver (*.mdb)".

If it's not there create that string value, and also the following entries
"{your_dsn_name}"="Microsoft Access Driver (*.mdb)"

Also add the following to define your dsn.
"FIL"="MS Access;"


I'm sure there's gotta be an easier way, but this is a method I've used before.

Expert Comment

ID: 9634730
Did you already tried it without this check?
As far as I know, if the DSN doesn't exists it is created automatically.
LVL 18

Expert Comment

ID: 9638085
Why not use a DSNless connection. All you have to do is create a connection string and open the connection object at runtime. In connection string you will pass all required parameters like data source name and username, passord etc. Here are two sites where you can find connection string for various databases:
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 18

Expert Comment

ID: 9638137
Here is an example:

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\My Documents\myDatabase.mdb;"
LVL 70

Expert Comment

by:Éric Moreau
ID: 9638179

Author Comment

ID: 9644621
emoreau, what is method for Access Database
LVL 70

Expert Comment

by:Éric Moreau
ID: 9644771

Author Comment

ID: 9646936
Not execute, the code is obsolete
LVL 70

Expert Comment

by:Éric Moreau
ID: 9647259

DSNs are obsolete! Is it working or not?
LVL 18

Expert Comment

ID: 9647299
Did you try DSNless connection as I mentioned above?

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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