如何在生成的数据集类中动态更改连接字符串? [英] How to dynamically change connection string in generated dataset class?

查看:75
本文介绍了如何在生成的数据集类中动态更改连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中包含从数据库对象生成的数据库类。那就是我将一个数据集添加到项目中,并将数据库对象拖放到它上面。这个问题是我必须给出一个存储在代码中的连接字符串。这在开发应用程序时是可以的。但运行时我想使用另一个连接字符串,这既是出于安全原因,也是因为应用程序的每个用户都对应一个数据库用户(ms sql),并且应该有一个相应的连接字符串。有没有一种简单的方法可以做到这一点,而无需恢复到所有数据集并自己做所有事情?

I have a project with database classes which are generated from database objects. That is I add a dataset to the project and drag and drop a database object onto it. The problem with this is that I have to give a connectionstring which is stored in the code. This is ok while developing the application. But runtime I want to use another connectionstring, both for security reasons and because each user of the application will correspond to a database user (ms sql) and shall have a corresponding connectionstring. Is there an easy way to do this without having to restore to plain all datasets and do everything myself?

推荐答案

当然可以。
您NBSP;可以在运行时从Web.config字符串获取它,或者您可以从您自己的配置文件中获取它。在打开SqlConnection(或IDbConnection)对象之前,只需获取连接字符串。

CESAR DE LA TORRE
[MVP - XML-WebServices]
软件架构师

www.renacimiento.com
Of course you can.
You  can get it at run-time from Web.config strings or you can get it from your own configuration file. Just get your connection string before opening the SqlConnection (or IDbConnection) object.

CESAR DE LA TORRE
[MVP - XML-WebServices]
Software Architect

Renacimiento 
www.renacimiento.com


这篇关于如何在生成的数据集类中动态更改连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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