• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

Automatically Create ODBC (system dsn) Data source

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
cantrell
Asked:
cantrell
1 Solution
 
simonsabinCommented:
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
 
cantrellAuthor Commented:
That creates a "File DSN". I need to create a "System DSN".
0
 
simonbennettCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now