views:

675

answers:

4

Traditionally, my client software forces a configuration of the ODBC source by going into 'Administrative Tools' and manually creating a new ODBC connection.

Is there anyway to configure a new ODBC connection during an install?

On a related note, is there a way to capture an existing ODBC connection for use in this theoretical process?

+1  A: 

Yes, there is. The entire ODBC object is stored in the Registry. You just have to create some Registry settings.

I'm assuming if you're still using ODBC, then you're stuck with Microsoft Access. Here are some example settings for Access. If your provider is different, let us know and we'll help with that, too.

Say your ODBC Connection name is MyODBC for these examples.

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources
Key:  "MyODBC"
Value: "Microsoft Access Driver (*.mdb)"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "FIL"
Value: "MS Access;"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "Driver"
Value: "$SYSDIR\odbcjt32.dll"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "Description"
Value: "Description you'd like your users to see in Control Panel"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "UID"
Value: The Access UserName if any.  This is optional.

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "DBQ"
Value: The installation directory/YourDB.mdb

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "SafeTransactions"
Value: "00000000"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC
Key: "DriverID"
Value: "00000019"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC\Engines\Jet
Key: "Threads"
Value: "00000003"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC\Engines\Jet
Key: "ImplicitCommitSync"
Value: ""

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC\Engines\Jet
Key: "UserCommitSync"
Value: "Yes"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC\Engines\Jet
Key: "PageTimeout"
Value: "00000005"

Section: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\MyODBC\Engines\Jet
Key: "MaxBufferSize"
Value: "00000800"

Of course, which installer you use will determine exactly how these are created.

Rap
this is important too because it defines the ODBC drivers on the system apparently.
entens
A: 

To answer my own question...

Each ODBC profile is found in:

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI

The profile contains the following:

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\<ODBC PROFILE NAME>]
"Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll"
"Server"="<ODBC PROFILE DSN>"
"LastUser"="<LAST USER TO ACCESS ODBC (probably for lock)>"
entens
+1  A: 

I've used the nullsoft installer back in the day and they have some sample scripts.

http://nsis.sourceforge.net/Create%5Fan%5FODBC%5Fentry%5Ffor%5Fa%5FMS%5FAccess%5Fdatabase http://nsis.sourceforge.net/Check%5Fwhether%5Fan%5FODBC%5Fentry%5Fexists

Basically you write to the correct values to the registry at: HKEY_LOCAL_MACHINE "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"

Use the registry tools included in your packaging software.

Which are you using? and What type of DB?

Lance Rushing
Its for deploying an ODBC connection to a SQL database for a legacy application that uses ADO for several operations we haven't quite updated yet.
entens
I'd create the connection manually on a test box, then export the corresponding entry from the test machine's registry. Save it as part of your deployment. Then use your installer's helpers (or command line) to import that tree during install.
Lance Rushing
A: 

Hi But there is Problem for Access Registry. If Admin Login then u can access registry,but for other user it is not.

Can u tell me how to add DSN at the installation time/Setup time.

Aniruddha Badawe