Setup An Odbc Connection Automatically

This script show you how to setup an ODBC connection without any user intervention. The script uses the Windows Registry and works on Windows 95/98/NT Declaration Event: Public Const REG_SZ = 1 'Unicode nul terminated string Public Const REG_DWORD = 4 '32-bit number Public Const HKEY_CURRENT_USER = &H80000001 Public Const HKEY_LOCAL_MACHINE = &H80000002 Public Const SYNCHRONIZE = &H100000 Public Const STANDARD_RIGHTS_ALL = &H1F0000...

Public Const STANDARD_RIGHTS_READ = &H20000 Public Const KEY_QUERY_VALUE = &H1 Public Const KEY_SET_VALUE = &H2 Public Const KEY_CREATE_SUB_KEY = &H4 Public Const KEY_ENUMERATE_SUB_KEYS = &H8 Public Const KEY_NOTIFY = &H10 Public Const KEY_CREATE_LINK = &H20 Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE)) Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE)) Public Const ERROR_SUCCESS = 0& 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 Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval lpReserved As Long, lpType As Long, Byval lpData As String, lpcbData As Long) As Long Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval dwType As Long, Byval lpData As String, Byval cbData As Long) As Long Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (Byval hKey As Long, Byval lpSubKey As String, phkResult As Long) As Long Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (Byval hKey As Long, Byval dwIndex As Long, Byval lpValueName As String, lpcbValueName As Long, Byval lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Sub Initialize() Dim session As New NotesSession Dim db As NotesDatabase Set db = session.CurrentDatabase Dim hKeyHandle As Long Dim RetType As Long Dim RetSize As Long Dim lValueLen As Long Dim lDataLen As Long Dim lpReturnedString As String*127 RetSize = 126 lngCurIdx = 0 lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" , 0, KEY_READ, hKeyHandle) 'Check if an ODBC Driver exist on the user workstation Do lValueLen = 2000 strValue = String(lValueLen, 0) lDataLen = 2000 lResult = RegEnumValue(hKeyHandle, lngCurIdx, Byval strValue, lValueLen, 0&, REG_DWORD, Byval lngData, lDataLen) lngCurIdx = lngCurIdx + 1 If Instr(1, strValue, "Lotus NotesSQL") Then lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBCINST.INI\" & strValue, 0, KEY_READ, hKeyHandle) lResult = RegQueryValueEx(hKeyHandle, "Driver", 0, RetType, lpReturnedString, RetSize) 'Specified the User DSN parameters DataSourceName = db.Title DatabaseName = db.FilePath DriverPath = lpReturnedString KeepTempIdx = "0" MapSpecialChars = "Y" MaxLongVarcharLen = "512" MaxRels = "20" MaxStmtLen = "4096" MaxSubquery = "20" MaxVarcharLen = "254" Server = db.Server ShowImplicitFlds = "0" ThreadTimeout = "60" DriverName = strValue 'Add the new ODBC connection key lResult = RegCreateKey(HKEY_CURRENT_USER, "SOFTWARE\ODBC\ODBC.INI\" & DataSourceName, hKeyHandle) lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, Byval DatabaseName, Len(DatabaseName)) lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, Byval <WHA

This was first published in November 2000

Dig deeper on Domino Resources

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close