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 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.