troubleshooting Question

Using an ADODB connection to query 2 different servers

Avatar of ADEZOYSA1
ADEZOYSA1 asked on
Visual Basic ClassicVB Script
9 Comments1 Solution235 ViewsLast Modified:
I am currently using ADODB connections to make my queries from VB6 to SQL servers.  My question is how do you make a statement that will reference 2 different SQL servers?  I want to eventually query one SQL server, take data from a particular table and then INSERT that into a different SQL server.

Below I have sample code that I use currently to transfer data from one table to another on the SAME SQL server.

    Set MyRec = CreateObject("adodb.recordset")
    MyConn.Open = "provider=SQLOLEDB;Server=testserver;database=Data1;user id=sa;password=test123"
    sSQL = "INSERT INTO [Data1].DBO.Table2_t "
    sSQL = sSQL & "SELECT [Data1].DBO.Table1_t.* "
    sSQL = sSQL & "FROM [Data1].DBO.Table1_t; "
    MyConn.commandtimeout = 0
    MyRec.Open sSQL, MyConn

"Batchelor", Developer and EE Topic Advisor

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2015

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros