Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatically Create ODBC (system dsn) Data source

Posted on 1999-08-17
3
Medium Priority
?
904 Views
Last Modified: 2008-03-04
Anyone know how to automatically create an ODBC ("System DSN") data source - like from a command line or batch file, or maybe a vb app?
0
Comment
Question by:cantrell
[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 7

Expert Comment

by:simonsabin
ID: 1099516
2 options
create a file dsn with the lines that you want i.e
[ODBC]
DRIVER=Microsoft Text Driver (*.txt; *.csv)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=25
MaxBufferSize=512
ImplicitCommitSync=Yes
FIL=text
Extensions=txt,csv,tab,asc
DriverId=27
DefaultDir=C:\TEMP
You can do this in VB using OPEN and Print. To see the format of one create an example using the ODBC control panel and you can find the file in
c:\program files\common files\odbc\data sources

Or you can remove the need for a DSN and build a DSN less connect sting i.e
"DRIVER=SQL SERVER;SERVER=MYServer;DATABASE=mydatabase;UID=;PWD="

0
 
LVL 2

Author Comment

by:cantrell
ID: 1099517
That creates a "File DSN". I need to create a "System DSN".
0
 
LVL 6

Accepted Solution

by:
simonbennett earned 200 total points
ID: 1099518
You can do this 2 ways,

1)Go to an existing System DSN (HKEY_LOCAL_MACHINE) in regedit, then right click on the entry an export it to a .reg file. Use notepad to open the .reg file and make the changes you need (name, driver etc). Now whenever that .reg file is run on a 9x or NT machine it will create the content (can be run from a batch file).

2)There are some api calls to enable you to create registry keys (can use VC or VB to do this). They are

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

..and..

Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long        

Eaxmple:

http://www.eu.microsoft.com/OfficeDev/Articles/ctrl_reg.HTM

Good Luck

Simon
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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