Add a DSN to the ODBC Administrator

Add a DSN to the ODBC Administrator

Post by Joe Klin » Sat, 14 Apr 2001 22:08:54



I can get a new new DSN to set up on the fly and have it entered into the
registry. I can get a DSN to write into the registry but I can't ever get
it to show as a system DSN in the "control panel|ODBC Data Source
Administrator" Any Ideas how I can go about this? This is very important.
Thank you very much. Here are some snippits:

DataSourceName = "MyDsn"
Engines = "Engines"
Jet = "Jet"
DBQPath = DataBaseLocation
Driver = "C:\Windows\system\odbcjt32.dll"
UID = ""
FIL = "MS Access;"
DriverId = &H19
SafeTransaction = &H0
ImplicitCommitSync = ""
MaxBufferSize = &H800
PageTimeOut = &H5
Threads = &H3
UserCommitSync = "yes"
Password = "password"

'Specify the DSN parameters.

'Create the new DSN key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & _
DataSourceName, hKeyHandle)

'DBQ
lResult = RegSetValueEx(hKeyHandle, "DBQ", 0&, REG_SZ, _
ByVal DBQPath, Len(DBQPath))

'Driver
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
ByVal Driver, Len(Driver))

lResult = RegSetValueExA(hKeyHandle, "DriverId", 0, REG_DWORD, DriverId,
4)  'write the value

'FIL
lResult = RegSetValueEx(hKeyHandle, "FIL", 0&, REG_SZ, _
ByVal FIL, Len(FIL))

lResult = RegSetValueExA(hKeyHandle, "SafeTransaction", 0, REG_DWORD,
SafeTransaction, 4)  'write the value

'Password
lResult = RegSetValueEx(hKeyHandle, "PWD", 0&, REG_SZ, _
    ByVal Password, Len(Password))

'UID
lResult = RegSetValueEx(hKeyHandle, "UID", 0&, REG_SZ, _
ByVal UID, Len(UID))

lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" &
DataSourceName & "\" & _
Engines, hKeyHandle)

lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" &
DataSourceName & "\" & Engines & "\" & _
Jet, hKeyHandle)

'ImplicitCommitsync
lResult = RegSetValueEx(hKeyHandle, "ImplicitCommitSync", 0&, REG_SZ, _
ByVal ImplicitCommitSync, Len(ImplicitCommitSync))

'MaxBufferSize
lResult = RegSetValueExA(hKeyHandle, "MaxBufferSize", 0, REG_DWORD,
MaxBufferSize, 4)  'write the value

'PageTimeOut
lResult = RegSetValueExA(hKeyHandle, "PageTimeOut", 0, REG_DWORD,
PageTimeOut, 4)  'write the value

'Threads
lResult = RegSetValueExA(hKeyHandle, "Threads", 0, REG_DWORD, Threads, 4)  
'write the value

'UserCommitSync
lResult = RegSetValueEx(hKeyHandle, "UserCommitSync", 0&, REG_SZ, _
ByVal UserCommitSync, Len(UserCommitSync))

'Close the new DSN key.
lResult = RegCloseKey(hKeyHandle)

'Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
'Specify the new value.
'Close the key.

lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, _
ByVal DriverName, Len(DriverName))
lResult = RegCloseKey(hKeyHandle)
MsgBox "The database located at """ & DataBaseLocation & """ was found
and a DSN was " _
& "set up", vbInformation + vbDefaultButton1 + vbOKOnly, "Success"

 
 
 

1. Failure to see System DSN in ODBC Administrator

I am having trouble setting up a System DSN in ODBC
Administrator.  I go through all of the setup steps,
including test connection (successful), but after
finishing, the DSN is not listed in the list of System
DSN's.  THis is on an XP Pro laptop connecting to a SQL
2000 Server,  I am using the Administrators UN & PW to
access the laptop.  I have setup several other laptops in
this environment (some W2K, some XP Pro) without problems,
but this one is giving me headaches.  Any ideas what might
be causing this?  Thanks.

2. ADO - zero length strings

3. no user, system or file DSN in odbc administrator

4. SQL Command Question

5. Failure to see System DSN in ODBC Administrator

6. sql server error 8630

7. SYSTEM DSN DOES NOT SHOW UP IN ODBC ADMINISTRATOR

8. SQL Srvr FAQ, online books here (free)

9. Adding SQL System DSN Changes Other DSN's from TCP\IP to Named Pipes

10. Add ODBC DSN programtically faided

11. Adding a new DSN to ODBC - Part 2