如何在一个asp.net项目中使用两个数据库连接 [英] how to use two database connections in one asp.net project

查看:395
本文介绍了如何在一个asp.net项目中使用两个数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助....
我想在我的asp.net项目中使用两个不同的数据库.意味着对于某些页面我要使用db.Test1,对于某些页面我要使用db.Test2.如何在一个项目中同时使用两个数据库连接.
在此先感谢...

pls help.......
i want to use two different database in my asp.net project. means for some pages i want to use db.Test1 and for some pages i want to use db.Test2. how can use both database connection in one project.
thanks in advance...

推荐答案

亲爱的朋友,

您可以在此处执行的操作是定义两个不同的变量以进行连接.设置数据库变量的值并从中建立连接.

当您要切换连接时,可以将数据库变量设置为其他数据库并建立其他连接,同时断开先前的连接.

完全取决于您的选择来打开多个数据库连接,但是为此您必须从数据库连接中创建两个不同的类,否则只有一个类会做.

希望您能理解我的意思.
Dear Friend,

What you can do here is that you can define two different variables for making connection. Set the value of database variable and make connection from it.

The moment you want to switch the connection then you can set the database variable to other database and make other connection while disconnecting the previous connection.

It totally depends on your choice to have multiple database connections open but for that you have to make two different classes from database connectivity else only one class will do.

I hope you understand what i am trying to say.


这篇关于如何在一个asp.net项目中使用两个数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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