本文介绍了多个数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在mvc应用程序中的按钮单击事件上获取添加连接提示,这是在我们尝试连接到数据库时出现的。

有没有办法实现这个目标?

最后,用户应该能够从网页连接到多个数据库,并查看可用的表和存储过程列表。 ...

I want to get the add connection prompt on a button click event in a mvc application, that comes when we try to connect to the database.
Is there any way to achieve this?
Finally the user should be able to connect to multiple databases from the webpage and see the list of tables and stored procedures available.....

推荐答案

<add name="DefectConnection">
			 connectionString="Data Source=SERVERNAME; Trusted_Connection=true;" providerName="System.Data.SqlClient"
				 /></add>





在运行时,您要添加数据库名称。因此,在代码中添加初始目录,如下所示:





At run time you want to add the database name. So add Initial Catalog within your code as below:

protected const string ConnectionStringKey = "DefaultConnection";
static string preConString = ConfigurationManager.ConnectionStrings[ConnectionStringKey].ConnectionString;
private static string conString = String.Format("{0};Initial Catalog={1}", preConString, "YOUR DATABASENAME");





您可以在此处使用配置设置获取连接名称,您可以使用要使用的数据库名称更改数据库名称。



您可以在代码中的任何地方使用它们。



您也可以使用多个连接字符串。



希望这会有所帮助。



Here you can use the configuration settings to get the connection name, you will be able to change the database name with the database name that you want to use.

You can use them within any place within your code.

Also you can use multiple connection strings as well.

Hope this will help.


这篇关于多个数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 12:51
查看更多