ODBC - How to create a DSN

From ISXKB

Jump to: navigation, search

A DSN ODBC on a PC are registry keys under SOFTWARE\ODBC\ODBC.INI, in HKLM for System DSN and in HKCU for User DSN. This MS KB article it's a sample on how to create a Data Source Name with Visual Basic.

Q184608 - HOWTO Programmatically Create a DSN for SQL Server with VB

If you want to create a DSN in your setup program with InnoSetup it's enough to include in the section [Registry] all registry key to create the DSN. It's a task not very easy but to avoid errors and problems you can follow these steps to get registry keys that you need, with help of ISTool.

  1. Create on your PC a DSN as you wish setup program ahe to create, Name and all settings
  2. Start ISTool and from menu Project select Create ODBC Profile... or in Registry section rigth-click and select Create ODBC Profile... A window will show all DSN on the PC, select the DSN previously created
  3. In the Registry section of the script will appear all registry setting of the DSN
  4. Change all path of the PC accordigly with InnoSetup constants as {app} or {sys}
  5. cut and paste this section in your InnoSetup script

The code below is a sample of importing a System DSN named ISXKBDB that refer a MS Access DB, after the import it's necessary to change the path of Driver, that from C:\WINDOWS\SYSTEM\ODBCJT32.DLL to {sys}\ODBCJT32.DLL. Same change for path of DB that from c:\Documenti\db\mydb.mdb change to {app}\db\mydb.mdb because the DB is installed in {app}\db.

[Files]
Source: C:\Documenti\db\mydb.mdb; DestDir: {app}\db

;
; Just Imported
;
[Registry]
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; ValueType: string; ValueName: ISXKBDB; ValueData: Microsoft Access Driver (*.mdb); Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; ValueType: string; ValueData: C:\WINDOWS\SYSTEM\ODBCJT32.DLL
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: DBQ; ValueType: string; ValueData: c:\Documenti\db\mydb.mdb
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Description; ValueType: string; ValueData: ISX Knowledge Base Database
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: DriverId; ValueType: dword; ValueData: 25
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: FIL; ValueType: string; ValueData: MS Access
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: SafeTransactions; ValueType: dword; ValueData: 0
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: UID; ValueType: string; ValueData:
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: ImplicitCommitSync; ValueType: string; ValueData:
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: MaxBufferSize; ValueType: dword; ValueData: 2048
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: PageTimeout; ValueType: dword; ValueData: 5
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Threads; ValueType: dword; ValueData: 3
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: UserCommitSync; ValueType: string; ValueData: Yes

;
; After changes
;
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ODBC Data Sources; ValueType: string; ValueName: ISXKBDB; ValueData: Microsoft Access Driver (*.mdb); Flags: createvalueifdoesntexist uninsdeletevalue
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Driver; ValueType: string; ValueData: {sys}\ODBCJT32.DLL
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: DBQ; ValueType: string; ValueData: {app}\db\mydb.mdb
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Description; ValueType: string; ValueData: ISX Knowledge Base Database
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: DriverId; ValueType: dword; ValueData: 25
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: FIL; ValueType: string; ValueData: MS Access
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: SafeTransactions; ValueType: dword; ValueData: 0
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: UID; ValueType: string; ValueData:
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: ImplicitCommitSync; ValueType: string; ValueData:
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: MaxBufferSize; ValueType: dword; ValueData: 2048
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: PageTimeout; ValueType: dword; ValueData: 5
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: Threads; ValueType: dword; ValueData: 3
Root: HKLM; SubKey: Software\ODBC\ODBC.INI\ISXKBDB\Engines\Jet; Flags: createvalueifdoesntexist uninsdeletevalue; ValueName: UserCommitSync; ValueType: string; ValueData: Yes
Personal tools
Ads: