Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have this application and i want user to decide which database they want to connect to at run time by supplying the data source,user id and password of the database before the application will run. i am using vb.net with oracle.any input will be appreciated. thanks. The following codes is what I have done but it does not seem to get me the result I want.
VB
Public Sub savenewconnection(ByVal id As String, ByVal pass As String, ByVal source As String)
       Try
           Dim newdbcon As String
           Dim oldconnection As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("mydbcon")
           Dim dbcon As String = oldconnection.ConnectionString
           Dim builder As New OleDbConnectionStringBuilder(dbcon)
           builder.Add("Data Source", source)
           builder.Add("Password", pass)
           builder.Add("User ID", id)
           newdbcon = builder.ConnectionString
           Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
           config.ConnectionStrings.ConnectionStrings("mydbcon").ConnectionString = newdbcon
           config.Save(ConfigurationSaveMode.Modified)
           ConfigurationManager.RefreshSection("ConnectionStrings")

       Catch ex As Exception
           MsgBox(ex.Message)
       End Try
   End Sub
Posted
Updated 15-Aug-12 10:42am
v2
Comments
[no name] 15-Aug-12 16:40pm    
Does screaming help get your point across?

1 solution

It is not possible to change the connection strings in your application config file at runtime. Quite simply because this is an application setting and not a user setting.
What you could do is simply use a real string and store that as a user setting.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900