如何连接不同的数据库运行时间 [英] how to connect different database dring run time

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

问题描述

在我的网络应用程序中,我希望在符文时间内连接requird数据库,或者如果我在web.config中有多个连接字符串,我希望与所需的连接如何访问整个Web应用程序







另一种方式,如果我有一个带有数据库名称的下拉框,我想连接该数据库如何connect

解决方案

你可以在web.config文件中的ur连接字符串中有多个数据库,然后你可能想要使用

 WebConfigurationManager .OpenWebConfiguration 

动态使用你想要的数据库。



配置configFile = System.Web.Configuration 

WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);

ConnectionStringsSection xxconnection =(ConnectionStringsSection)configFile.GetSection( connectionStrings) ;

xxconnection.ConnectionStrings [ X]。ConnectionString = Y;

Response.Write( < script> alert('I got it'); < /脚本>中);

configFile.Save();





我之前没用过它。它可能适合你.. :)


也许它可以帮到你:

http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/1f931fdd-09de-4413-b8d0-b3d582b92f84 [ ^ ]

In my web application i want to connect with requird database during rune time or if i am having multible conection string in web.config and i want the coonect to the requried one how to acces for whole web application



in another way if i am having one drop down box with database name and i wann connect with that database how to connect

解决方案

you can have multiple databases in ur connection string in the web.config file and then you might want to use the

WebConfigurationManager.OpenWebConfiguration

to dynamically use the database which you want.

 Configuration configFile=System.Web.Configuration

WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
 
 ConnectionStringsSection xxconnection= (ConnectionStringsSection)configFile.GetSection("connectionStrings");
 
 xxconnection.ConnectionStrings["X"].ConnectionString = "Y"; 
 
Response.Write("<script>alert ('I got it');</script>"); 
 
configFile.Save();



I havent used it earlier.It might work for you.. :)


Maybe it could help you :
http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/1f931fdd-09de-4413-b8d0-b3d582b92f84[^]


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

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