如何更改VB 2010中保存在My.Settings中的连接字符串 [英] How To Change The Connection String saved in My.Settings in VB 2010

查看:78
本文介绍了如何更改VB 2010中保存在My.Settings中的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,并使用向导创建了自动创建自己的xml代码的数据集。此代码使用保存在My.Settings连接字符串中的代码。作为应用程序范围不可更改的设置,我无法在运行时更改其值。
问题是当我向客户安装应用程序时,连接字符串将不得不更改(可能不止一次)。那么有没有办法在运行时更改这些对象使用的连接字符串?

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 ?

推荐答案

下面是如何通过代码编辑设置的方法:

Here's how to edit the setting via code:

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

但是,更简单的解决方案是只使用 app.config 文件。向导创建数据集时,应将连接字符串添加到 app.config 中,该字符串将作为< assemblyName>复制到项目的输出目录中; .config 。然后,安装程序可以确定正确的连接字符串并自动编辑 .config 文件。另外,您的用户可以手动编辑配置文件。

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.

这篇关于如何更改VB 2010中保存在My.Settings中的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆