如何在运行时更改数据库 [英] How to Change a Database at Runtime

查看:143
本文介绍了如何在运行时更改数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在编写一个程序,该程序需要用户从运行时生成的列表中选择一个数据库.该列表由单个表数据库组成,该表数据库包含目录中所有数据库的文件路径.问题是,我无法更改App.config文件中的连接字符串,只能在vshost.exe.config中进行更改.另外,settings.settings文件还具有需要更改的连接字符串.有没有办法改变这些事情,或者有更简单的办法随时更改数据源?

任何帮助将不胜感激:)

Hi there,

I''m writing a program that needs the user to select a database from a list generated at runtime. The list is made from a single table database that contains the filepaths of all the databases in a directory. The problem is, I cannot change the connection string in the App.config file, I can only change it in the vshost.exe.config. Also, the settings.settings file has connection strings that need to be changed as well. Is there a way to change these things, or is there an easier way to change a datasource on the fly?

Any help would be very much appreciated :)

推荐答案

只需更改代码从何处获取数据源即可.您可以从任何地方获取连接字符串,并且可以按自己喜欢的任何方式存储它们的选择.
Simply change where your code takes it''s data source from. You can get a connection string from anywhere, and you can store their selection any way you like.


更改从何处获取连接数据的位置基本上意味着重写.我知道糟糕的情况,但我对此感到困惑"

如果代码如此糟糕,则可能需要重写.但是,您确定可以找到查找连接字符串的位置,并进行搜索和替换以将其替换为单个属性访问权限,从而使您将来可以在单个位置更改连接字符串吗?
"To change where it gets the connection data from would basically mean a rewrite. I know it''s a crappy situation but I''m quite baffled by this"

If the code is that terrible, perhaps a rewrite is what''s needed. But, surely you can find the places that look up the connection string, and do a search and replace to replace them all with a single property access, allowing you to change the connection string in a single place in future ?


为使其持久,我将其移至配置文件(可能是XML)中.
Well, for it to persist, I''d be moving it to a config file, probably XML.


这篇关于如何在运行时更改数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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