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
Solved

how can i create a DSN in runtime

Posted on 2003-10-28
10
452 Views
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
0
Comment
Question by:darknighter
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 9

Accepted Solution

by:
_ys_ earned 125 total points
ID: 9634203
Check under the registry key
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
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
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
"{your_dsn_name}"="Microsoft Access Driver (*.mdb)"

Also add the following to define your dsn.
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\{your_dsn_name}]
"Driver"="C:\\{your_system_32_directory}\\odbcjt32.dll"
"DBQ"="C:\\{complete_path}\\{file_name}.mdb"
"Description"="{whatever}"
"DriverId"=dword:00000019
"FIL"="MS Access;"
"SafeTransactions"=dword:00000000
"UID"=""

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\{your_dsn_name}\Engines]
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\{your_dsn_name}\Engines\Jet]
"ImplicitCommitSync"=""
"MaxBufferSize"=dword:00000800
"PageTimeout"=dword:00000005
"Threads"=dword:00000003
"UserCommitSync"="Yes"


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

Expert Comment

by:marcomania
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.
0
 
LVL 18

Expert Comment

by:Sethi
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:
http://www.connectionstrings.com
http://www.able-consulting.com/ADO_Conn.htm
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 18

Expert Comment

by:Sethi
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;"
cnn.Open
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9638179
0
 

Author Comment

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

Expert Comment

by:Éric Moreau
ID: 9644771
0
 

Author Comment

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

Expert Comment

by:Éric Moreau
ID: 9647259
???

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

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

856 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