Private Function CreateDSN(ByVal DB_Name As String, _
ByVal DSN As String, _
ByVal Description As String, _
ByVal Driver_Name As String, _
ByVal userid As String, _
ByVal password As String, _
ByVal Server_Name As String, _
ByVal port As String, _
ByVal stroption As String, _
ByVal stmt As String _
) As Boolean
Dim lResult As Long
Dim hKeyHandle As Long
Dim msg1 As String
Dim regHandle As RegistryKey ' Stores the Handle to Registry in
which values need to be set
Dim reg As RegistryKey = Registry.LocalMachine
Dim conRegKey1 As String = "SOFTWARE\ODBC\ODBC.INI\" & DSN
Dim conRegKey2 As String = "SOFTWARE\ODBC\ODBC.INI\ODBC Data
Sources"
Try
regHandle = reg.CreateSubKey(conRegKey1)
regHandle.SetValue("Database", DB_Name)
regHandle.SetValue("Description", Description)
regHandle.SetValue("Driver", Driver_Name)
regHandle.SetValue("Option", stroption)
regHandle.SetValue("Password", password)
regHandle.SetValue("Port", port)
regHandle.SetValue("Server", Server_Name)
regHandle.SetValue("Stmt", stmt)
regHandle.SetValue("User", userid)
regHandle.SetValue("LastUser", userid)
regHandle.Close()
reg.Close()
regHandle = reg.CreateSubKey(conRegKey2)
regHandle.SetValue(DSN, "SQL SERVER")
regHandle.Close()
reg.Close()
Catch err As Exception
End Try
End Function
if there is an existing DSN, it will overwite it.
HTH