Create ODBC DSN
Posted by: fredometro on
Jan 1st, 2004 |
Filed under: MS-Access
Creates a system ODBC DSN thru a program.
As you can see, we create the DSN by making an entry in the registry.
In your Project you need Form1 and a command button Command1. Here’s the code for the General Declarations:
Option Explicit
Private Const REG_SZ = 1 ‘Constant for a string variable type.
Private Const HKEY_LOCAL_MACHINE = &H80000002
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
Next go to the click event of the Command1 button and enter the following:
Private Sub Command1_Click()
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 lResult As Long
Dim hKeyHandle As Long
’Specify the DSN parameters.
DataSourceName = ” ”
DatabaseName = “”
Description = “”
DriverPath = ” ”
LastUser = “”
Server = “”
DriverName = “SQL Server”
’Create the new DSN key.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, “SOFTWARE\ODBC\ODBC.INI\” & _
DataSourceName, hKeyHandle)
’Set the values of the new DSN key.
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 Sub


December 12th, 2009 at 12:42 am
Amateur Nuts
December 12th, 2009 at 12:43 am
Spank Hut
December 12th, 2009 at 12:44 am
Feith Belle
December 12th, 2009 at 12:45 am
Cum Loving Petites
December 12th, 2009 at 12:46 am
Buttman
December 12th, 2009 at 12:47 am
Ripping Bungholes
December 12th, 2009 at 12:48 am
Shemale Thrills
December 12th, 2009 at 12:50 am
Evah Ellington
December 12th, 2009 at 12:51 am
Mega Porn Mall
December 12th, 2009 at 12:52 am
Whats Your Kink
December 12th, 2009 at 12:53 am
Jennifer Colombiana
December 12th, 2009 at 12:54 am
Dad Shags Chick
December 12th, 2009 at 12:55 am
Cum On These Feet
December 12th, 2009 at 12:56 am
Naughty Pumpkins
December 12th, 2009 at 12:57 am
Katsuni
December 12th, 2009 at 12:58 am
Felony Angel
Add A Comment
You must be logged in to post a comment.