ADEZOYSA1
asked on
Using an ADODB connection to query 2 different servers
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.record set")
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
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.record
MyConn.Open = "provider=SQLOLEDB;Server=
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
ASKER
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
However, I want to do this directly from VB6.
Is there a way to reference the LINKS within VB6?
Thanks
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\instanceNa me].DB2.Sc hema.Tbl2 select * from DB1..Tbl1
insert into [MySecondServer\instanceNa
As soon as you have defined the Linked Server entry, you can use it in any SQL tool or programming language, including VB6.
ASKER
makes sense, let me try this and I will let you know.
ASKER
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?
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?
No clue. You are, of course, trying to access MSSQL, do you?
ASKER
Yes that is correct. One server is SQL 2000 and the other is SQL 2008 R2.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please see this Microsoft article for detailed information.