Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How to can create a ODBC DSN connection from file .bat at Windows? ¿ Is possible ?

share|improve this question
    
.bat only gives you access to what is at command line, so I don't think it's possible. It should be possible with visual basic though, although I've never done it. –  Robert Sep 25 '12 at 23:04
    
@Robert That's possible. Already did. –  Jhonathan Sep 26 '12 at 14:06
add comment

1 Answer

up vote 5 down vote accepted

Sure.

Manually create an ODBC connection on your PC using the "Data Sources (ODBC)" applet in Admin tools.

Launch regedit and go to HKLM\Software\ODBC and export the whole lot from ODBC down to a .reg file. This is a right click option on the folder.

Open the exported file in Notepad now you need to delete everything that doesn't refer to your particular ODBC connection.

You should end up with a registry file looking something like this

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
"TEST"="SQL Server"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\TEST]
"Driver"="C:\\Windows\\system32\\SQLSRV32.dll"
"Server"="SERVERNAME"
"LastUser"="USERNAME"
"Trusted_Connection"="Yes"

It may be slightly different depending on connection settings and such like. You will need the two sections, the data sources defines the type of connection, in this instance a SQL server one, then the bit that tells you what it is called, which driver to use and what sort of authentication to use. this will all be done when you set up the connection, you just need the .reg file with it in.

You can then import it on any pc by either double clicking the reg file or if you have the facility run a script to import it using regedit. You can call this import from a batch file:

regedit /s FileToImport.reg
share|improve this answer
4  
Be careful: there are two sets of registry keys for odbc connections on 64bit machines. –  Joel Coel Sep 4 '12 at 18:44
    
The registry entries can also be created with reg.exe. If you're going to move a file around anyway, it might be better to create a file DSN instead of a system DSN. –  Ansgar Wiechers Sep 4 '12 at 20:12
    
works! I opened ran regedit and exported the current dsn to make a copy to install on other machines. –  crh225 Jan 15 '13 at 19:05
2  
Note for 32-bit programs running on 64-bit systems the path is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\.... –  Nux May 6 at 14:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.