如何在linq中动态更改连接字符串到sql? [英] How to change connection string dynamically in linq to sql ?

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

问题描述

Hii,



i在我的confi文件中定义了一个连接字符串..



但是基于根据要求我正在获取其他连接字符串我正在做以下...



MyDataContext context = new MyDataContext(connectionString);



对于特定范围来说是暂时的......还是会在整个应用程序中设置新的连接..



希望它会恢复到默认状态。 。$



请建议//

Hii ,

i have one connection string defined in my confi file ..

but based on requirement i am fetching other connection string i am doing following ..

MyDataContext context = new MyDataContext(connectionString);

will it be temporary for perticular scope .. or will it set new connection through out the application ..

hope it will get back to default .. ??

please suggest //

推荐答案

每个数据上下文都使用连接字符串。在没有任何参数的情况下调用的数据上下文将使用配置文件中的连接字符串,但使用指定连接字符串创建的数据上下文将使用该连接字符串而不影响默认连接字符串。
Each data context use a connection string. The data context invoked without any parameter will use the connection string from your configuration file, but the data context created with a specified connection string will use that connection string without to affect the default one.


你好Torakami先生

请参阅此解决方案:

通过编程动态更改LINQ连接字符串
Hello Mr. Torakami
Please See This Solution :
Change LINQ Connection String Dynamically with Programming


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

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