ASP.net连接到两个数据库一次? [英] ASP.net Connecting to two databases at once?
问题描述
是连接两个SQL数据库在同一时间可以吗?我的意思是从一个数据库我读的记录,并将它们与如电子邮件地址的一些数据进行比较,并基于该数据库中是否存在该电子邮件地址,我存储新的记录在另一个数据库的决定。
Is connecting to two SQL databases at the same time possible ? I mean from one database I am reading records and comparing them with some data like email address and based on the decision that whether that email address exists in the database or not I am storing a new record in another database.
就是这种双操作的可能?
Is this kind of double operation possible ?
我使用的SqlConnection数据库连接和的SqlCommand声明
I am connecting with databases using SqlConnection and SqlCommand statements of C#.net
感谢您。
推荐答案
是的,这是可能的。
您可以返回一个值的asp.net应用程序,然后连接到另一个数据库,如:
You can either return a value to your asp.net application, and then connect to another database like:
cmdEmailExists SqlCommand = new SqlCommand("SQL HERE...", Conn1);
if (((int)cmdEmailExists.ExecuteScalar())>0){
cmdInsert SqlCommand = new SqlCommand("SQL INSERT HERE...", Conn2)
cmdInsert.ExecuteNonQuery();
}
其中, CONN1
和连接2
2种不同的的SqlConnection
的连接到2个不同的数据库。
Where Conn1
and Conn2
are 2 different SqlConnection
's connecting to 2 different databases.
或者这可以在SQL年底完成一样:
Or this can be done at SQL end like:
IF EXISTS(SELECT Email FROM [Database1].dbo.tbl)
BEGIN
INSERT INTO [Database2].dbo.tbl ..........
END
这篇关于ASP.net连接到两个数据库一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!