Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
"ExampleDSN"="SQL Server"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ExampleDSN]
"Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll"
"Description"="To give details"
"Server"="ServerName"
"QuotedId"="No"
"AnsiNPW"="No"
"Database"="AdventureWorks"
"LastUser"="sa"
"AutoTranslate"="No"
If you want default to Windows/AD Authentication add
"Trusted_Connection"="Yes"Option Compare Database
Option Explicit
Private Const REG_SZ = 1 'Constant for a string variable type.
'If you would want to create a User DSN instead of a System DSN you
would uncomment the HKEY_CURRENT_USER below and comment out the
HKEY_LOCAL_MACHINE. Then you would need to do a replace of the
HKEY_LOCAL_MACHINE with HKEY_CURRENT_USER Also replace HKLM with
HKCU.
Private Const HKEY_LOCAL_MACHINE = &H80000002
'Private Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias _
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal reserved As Long, ByVal dwType As Long, lpData As Any, ByVal _
cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
'This function is designed for creating system level ODBC calls to MS SQL _
Server databases on the fly.
'The form events are listed below in the order that they occur. The call to _
this function has to be done in the Open Event, because the Load Event is _
where it will attempt to use the ODBC call to start pulling in data.
'Open Þ Load Þ Resize Þ Activate Þ Current
Dim DataSourceName As String
Dim DatabaseName As String
Dim Description As String
Dim DriverPath As String
Dim DriverName As String
Dim LastUser As String
Dim Regional As String
Dim Server As String
Dim AddSetup As String
Dim YesAnswr As String
Dim lResult As Long
Dim hKeyHandle As Long
'Specify the DSN parameters.
DataSourceName = "MySystemDSN" '<--- The name of the ODBC Call. (1) See below.
DatabaseName = "MyDBName" '<--- This is the database you are targeting.
Description = "My DSN Description" '<--- (2) See below.
DriverPath = "C:\WINDOWS\system32" '<--- Default value. Don't change it.
LastUser = "sa" '<--- This can be any valid SQL Userid.
Server = "MyServerName" '<--- The server or DNS value you are targeting.
DriverName = "SQL Server" '<--- Default value. Don't change it.
AddSetup = "No" '<--- This is for Additional Setup Options
YesAnswr = "Yes" '<--- This is for Trusted Connection
'(1) This is what you want the ODBC call to be named, such as "VDW" or _
"ISIR". You do need to be aware that if you are putting a front-end _
on a delivered application that you are not overwriting some setting _
that the application comes with. You can check this by looking at _
at a workstation that the application is installed on.
'(2) Description: This is optional, but if you don't use it delete it _
in the set values section below, or change it to a single space.
'Create the new DSN key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & _
DataSourceName, hKeyHandle)
'Set the values of the new DSN key.
'The first three below (QuotedId, AnsiNPW, AutoTranslate) are optional depending _
on the ODBC setup that you are creating. If you were setting up an ODBC call _
manually on the second to last page it has check boxes for _
Use ANSI quoted identifiers. = QuotedId _
Use ANSI nulls, paddings and warnings. = AnsiNPW _
and on the last page it has a check box for _
Perform translation for character data. = AutoTranslate _
On our home grown databases and many of our delivered ones these are turned off _
by default. If they would need to be turned on (checked), you just delete the _
line that matches it.
'Uncomment the Trusted_Connection line below to default the ODBC call to _
use Windows Authentication instead of SQL Authentication.
'lResult = RegSetValueEx(hKeyHandle, "Trusted_Connection", 0&, REG_SZ, _
ByVal YesAnswr, Len(YesAnswr))
lResult = RegSetValueEx(hKeyHandle, "QuotedId", 0&, REG_SZ, _
ByVal AddSetup, Len(AddSetup))
lResult = RegSetValueEx(hKeyHandle, "AnsiNPW", 0&, REG_SZ, _
ByVal AddSetup, Len(AddSetup))
lResult = RegSetValueEx(hKeyHandle, "AutoTranslate", 0&, REG_SZ, _
ByVal AddSetup, Len(AddSetup))
lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, _
ByVal DatabaseName, Len(DatabaseName))
lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, _
ByVal Description, Len(Description))
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
ByVal DriverPath, Len(DriverPath))
lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, REG_SZ, _
ByVal LastUser, Len(LastUser))
lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, _
ByVal Server, Len(Server))
'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)
End Function
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (5)
Commented:
Commented:
Use WMI to do remote desktop changes.
Commented:
I have installed Oracle drivers 11.2 R2 and can use Netmanager to test configurations but I can't get the ODBC Data Source administrator to show the Oracle driver.
Commented:
Commented: