Cómo cambiar la cadena de conexión guardada en My.Settings en VB 2010

I am writting an application and I used Wizard to create DataSets which auto-created their own xml code. This code uses the saved in My.Settings Connection String. Being a setting with an unchangable 'Application' scope i cannot change its value at runtime. The problem is that when I install the Application to my customer the Connection String will have to change (maybe more than once). So is there a way to change the Connection String used by these objects at runtime ?

preguntado el 30 de enero de 12 a las 19:01

1 Respuestas

Here's how to edit the setting via code:

My.Settings.Item("ConnectionString") = "some connection string"

However, an easier solution would be to just use the app.config file. When the wizard creates your DataSets it should be adding the connection strings to app.config, which will get copied to your project's output directory as <assemblyName>.config. Then your installer could determine the proper connection string and edit the .config file automatically. Also, your users could edit the config file manually.

Respondido el 27 de junio de 13 a las 18:06

For the time being I just tried with success the first solution. - paulcheil

I have some things to ask about the second solution but I should first try out a few things and save some of your time. Thank you Dennis. But why is My.Settings.Item("ConnectionString") = "new conn str" allowed and My.Settings.ConnectionString = "new conn str" not allowed ? Tried them both and the compiler says its a read only property using this syntax. I mean i get the job done but now I answered a question and created another one !! :) - paulcheil

Your second question is exactly my question. @dennis Can you answer this, mate? - Mohammed Julfikar Ali Mahbub

Hey @coderDennis I found that using your method actually do change the value but when we restart the application it resets to its default value again. - Mohammed Julfikar Ali Mahbub

Por cierto, el .Item part is optional: My.Settings("ConnectionString") = o solo My.Settings!ConnectionString = docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/… - Slai

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.