在测试数据库和生产数据库之间切换 [英] Switching between test and production databases

查看:293
本文介绍了在测试数据库和生产数据库之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我有一个关于如何在Windows窗体应用程序中的测试数据库和生产数据库之间进行切换的问题.因此,我构建了一个在测试数据库中插入cerain值的应用程序(从xml读取内容并在数据库中写入结果).我通过数据集访问数据库(我将表从VS中的数据库connectino拖到数据集的后缀上).我的问题是,有没有一种方法可以在生产和测试数据库之间进行切换,而不必创建新表,数据集或更糟的是整个新应用程序.我读了一些有关仅切换ConnectionStrings(初始目录)的信息,尽管它不会引发错误,但在我指定的数据库中什么也没有发生.

提前谢谢!
B

Hello!

I have a question about how to change between test and production databases in a windows forms app. So I built an app that inserts cerain values in a test database (reads someting from an xml and writes the resoults in the DB). I access the database thrugh the dataset(I draged the table from database connectino in VS onto the sufrace of the dataset). My question is, is there a way to switch betwen the production and test DB without having to create a new table, dataset or worse, an entire new app. I read something about just switching ConnectionStrings (initial catalog), although it does not throw an error nothing happenes in the database I specified.

Thanks in advance!
B

推荐答案



使用以下技术进行相同的操作.

Hi,

Use the below technique to do the same.

public static string GetConnectionString()
{
    #if (DEBUG)
      return testConnectionString;
    #else
      return productionConnectionString;
    #endif
}



要更改模式,请执行以下步骤.

1.右键单击根项目.
2.选择属性
3.选择配置
4.将所有配置更改为Release
5.单击应用",单击确定"

重新运行该应用程序.

希望对您有帮助.



To change the mode follow the below step.

1. Right click on root project.
2. Select properties
3. Select configuration
4. Change all the configuration to Release
5. Click Apply, Click Ok

Re-Run the application.

Hope this will help you.


使用Cofiguration Manager将数据库的两个连接字符串保存在 web.config App.config文件中.
根据您的要求,使用if条件将Connection字符串分配给SqlConnectio对象.
Save both Connection strings of the databases in the web.config App.config file using Cofiguration Manager.

based on your requirement use the if condition to assign Connection string to the SqlConnectio object.


这篇关于在测试数据库和生产数据库之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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