如何连接不同的数据库运行时间

编程入门 行业动态 更新时间:2024-10-26 16:34:32
本文介绍了如何连接不同的数据库运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的网络应用程序中,我希望在符文时间内连接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.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 : social.msdn.microsoft/Forums/en/adodotnetentityframework/thread/1f931fdd-09de-4413-b8d0-b3d582b92f84[^]

更多推荐

如何连接不同的数据库运行时间

本文发布于:2023-11-30 21:39:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!