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.LocalM achine
Dim conRegKey1 As String = "SOFTWARE\ODBC\ ODBC.INI\" & DSN
Dim conRegKey2 As String = "SOFTWARE\ODBC\ ODBC.INI\ODBC Data
Sources"
Try
regHandle = reg.CreateSubKe y(conRegKey1)
regHandle.SetVa lue("Database", DB_Name)
regHandle.SetVa lue("Descriptio n", Description)
regHandle.SetVa lue("Driver", Driver_Name)
regHandle.SetVa lue("Option", stroption)
regHandle.SetVa lue("Password", password)
regHandle.SetVa lue("Port", port)
regHandle.SetVa lue("Server", Server_Name)
regHandle.SetVa lue("Stmt", stmt)
regHandle.SetVa lue("User", userid)
regHandle.SetVa lue("LastUser", userid)
regHandle.Close ()
reg.Close()
regHandle = reg.CreateSubKe y(conRegKey2)
regHandle.SetVa lue(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