|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Update ODBC DSN Properties in VB.NET Code?I have a DSN that I frequently have to change the default database. Is
there a way to do this in VB.NET code instead of having to go through the setup wizard every time? Try using an API call to SQLConfigDataSource; although this solution is not
specific to VB.Net, it will solve your problem. <za***@construction-imaging.com> wrote in message Show quoteHide quote news:1147965666.077965.217700@j55g2000cwa.googlegroups.com... >I have a DSN that I frequently have to change the default database. Is > there a way to do this in VB.NET code instead of having to go through > the setup wizard every time? > 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 I should have known that this info was simply stored in the registry.
Thanks for the pointer and the sample code.
Possible to set/reference a property 'dynamically'?
Checked Listbox? network programming with vb Error that I can't figure out Moving Splitter Throws Exception Can't seem to get AcceptButton working when changed in code? Form getting maximize PictureBox with shortcut possible? Simple Question about two forms Cannot fully access My namespace facility in VS 2005 |
|||||||||||||||||||||||