?
Solved

Using an ADODB connection to query 2 different servers

Posted on 2014-11-10
9
Medium Priority
?
182 Views
Last Modified: 2014-11-14
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
    MyConn.Close

Thanks
0
Comment
Question by:ADEZOYSA1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 11

Expert Comment

by:John Easton
ID: 40433035
It sounds like the best option is to create a linked server.  This would allow you to access data on the second server by using table names like [SRVR002].database.dbo.table from the server you are connected to.

Please see this Microsoft article for detailed information.
0
 

Author Comment

by:ADEZOYSA1
ID: 40433051
I thought of that as well.  And I believe it works well when you create the LINKS and then use that within the SQL Management's Query area.

However, I want to do this directly from VB6.

Is there a way to reference the LINKS within VB6?

Thanks
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40433077
You can set up a Linked Server on one of both MSSQLs. That allows the server the link is defined in to connect to the other one with something like
  insert into [MySecondServer\instanceName].DB2.Schema.Tbl2 select * from DB1..Tbl1
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Qlemo
ID: 40433083
As soon as you have defined the Linked Server entry, you can use it in any SQL tool or programming language, including VB6.
0
 

Author Comment

by:ADEZOYSA1
ID: 40433084
makes sense, let me try this and I will let you know.
0
 

Author Comment

by:ADEZOYSA1
ID: 40435070
Qlemo,

I first created the LINKED server and then tried the reference in my code and got INVALID OBJECT NAME.

So just to make sure that I got the LINK correct.  I went into the SQL Server Management and then created a simple SELECT on the "linked" tables and got the following:

OLE DB provider "SQLNCLI10" for linked server "SRV-NEWANA" returned message "Unspecified error".
OLE DB provider "SQLNCLI10" for linked server "SRV-NEWANA" returned message "The stored procedure required to complete this operation could not be found on the server. Please contact your system administrator.".
Msg 7311, Level 16, State 2, Line 1
Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI10" for linked server "SERVER1". The provider supports the interface, but returns a failure code when it is used.


Any ideas?
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40435582
No clue. You are, of course, trying to access MSSQL, do you?
0
 

Author Comment

by:ADEZOYSA1
ID: 40435618
Yes that is correct.  One server is SQL 2000 and the other is SQL 2008 R2.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40436110
I've just tried that (again). No issues with a link to MSSQL 2000 in MSSQL 2008r2. Maybe an issue with the (underprivleged) db user?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question