本文介绍了如何连接不同的数据库运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网络应用程序中,我希望在符文时间内连接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();我之前没用过它。它可能适合你.. :)
也许它可以帮到你: social.msdn.microsoft/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.OpenWebConfigurationto 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 : social.msdn.microsoft/Forums/en/adodotnetentityframework/thread/1f931fdd-09de-4413-b8d0-b3d582b92f84[^]更多推荐
如何连接不同的数据库运行时间
发布评论