Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 31-Aug-17 17:29pm

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
Member 11856456 31-Aug-17 13:30pm    
I will look more into doing separate connections thanks for the info.
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900