你有一个SQL双连接字符串吗? [英] Can you have a SQL dual connection string

查看:75
本文介绍了你有一个SQL双连接字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个允许我在vb.net中将表从一个数据库传输到另一个数据库的sql语句。我遇到的问题是我连接到1个数据库的连接字符串。有什么我可以添加到它连接到两个所以我可以转移表格吗?



我尝试过:



我试图创建一个额外的sql连接字符串,但这不是我想要做的。

I am looking to make an sql statement that allows for me to transfer tables from one database to another in vb.net. The problem I am having is that the connection string I have connects to 1 database. is there something I can add to it to connect to both so I may transfer tables?

What I have tried:

I have tried to make an additional sql connection string, but it's not exactly what I am wanting to do.

推荐答案

没有这样的东西。



您必须创建两个连接字符串,每个数据库一个,以及两个连接对象,每个数据库一个。您将从一个数据库中读取数据,对数据执行所需的任何处理,然后将该数据写入另一个数据库。
There is no such thing.

You have to create two connection strings, one for each database, and two connection objects, one for each database. You're going to read the data from one database, do any processing you need to with the data, then write that data to the other database.


看一下:

如何通过一个连接字符串Sql和Vb.Net连接两个不同的数据库 - Stack Overflow [ ^ ]



如果上面的答案中的两个不同的服务器情况就是你的情况,那么我担心除了两个不同的SqlConnections与不同的连接字符串之外别无选择。
Take a look here:
How to connect with two different databases by one connection string Sql and Vb.Net - Stack Overflow[^]

If the "two different servers" case in the above answer is your case, then I'm afraid that there is no alternative than having two different SqlConnections with different connection strings.


正如所指出的,如果你想从客户端程序与两个不同的数据库进行通信,你需要两个连接,因此需要两个连接字符串。



但是,因为你要将数据从一个数据库移动到另外,我会考虑不通过客户端程序传输数据。当您使用客户端程序时,首先需要将数据读入程序,或者处理它,然后将其写入另一个数据库。



相反,我建议使用链接服务器。链接服务器是服务器端对象,可用于直接从数据库与另一个数据库进行通信。我相信这种方法会更简单,也更有效。在最好的情况下,您可以使用简单的 INSERT INTO ... SELECT FROM 结构来传输数据。



有关详细信息,请查看链接服务器(数据库引擎)| Microsoft Docs [ ^ ]
As pointed out, if you want to communicate with two different databases from a client program, you need two connections thus two connection strings.

However, since you're moving data from one database to another, I would consider not transferring the data via a client program. When you use a client program you first need to read the data into the program, perhaps process it and then write it to the other database.

Instead, I would suggest using a linked server. A linked server is a server side object that can be used to communicate directly from a database to another. I believe that this approach would be more straightforward and also more efficient. In the best case you could perhaps use a simple INSERT INTO ... SELECT FROM structure to transfer the data.

For more information, have a look at Linked Servers (Database Engine) | Microsoft Docs[^]


这篇关于你有一个SQL双连接字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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