I'm trying to copy data from one table on SQL Server 2012 into another table on remote server (Azure)
Azure is added as linked server on SQL Server 2012
I'm creating XML statements for inserts and then executing those statements on remote server as mentioned below.
DECLARE @xml XML
SET @xml = (
SELECT 'insert into Table_on_Azure values (' + convert(varchar(300),isnull(ID, 'NULL')) + ',' + convert(varchar(300),isnull(ST_ID, 'NULL')) + ',' ..... etc etc ...');'
FROM local_table
FOR XML path('')
)
DECLARE @sql AS VARCHAR(max)
SET @sql = 'set nocount on;' + cast(@xml AS VARCHAR(max)) + 'set nocount off;' --Converts XML back to a long string
EXEC ('select * from remote_table_2') AT Linked_Azure_Server -- To confirm that the Linked Server is working fine and yes I do get results from this.
EXEC ('use myRemoteDB;' + @sql ) AT Linked_Azure_Server
The reason why I'm doing this is : "The local table has around 1 million records and it was taking me more than 3 hours to push the data onto Linked Server. Then I found this answer Linked Server Insert-Select Performance in which it was suggested to create XML insert statements and execute on remote server.
But When I'm doing this I'm getting below error
OLE DB provider "SQLNCLI11" for linked server "Linked_Azure_Server" returned message "Communication link failure".
TCP Provider: The specified network name is no longer available.
I'm sure the link to Linked_Server is fine. To cross check I wrote this statement EXEC ('select * from remote_table_2') AT Linked_Azure_Server
just before inserting records and I do get results from this.
I've checked other answers to similar questions related to Communication Link Failure
but no one is really helpful.