Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an Error on inserting data when using Linked Server Queries

UPDATE : The issue was col1 was hiereachyid type and even a select didnt work for it.

Hi all,

I am getting this error -

Objects exposing columns with CLR types are not allowed in distributed queries. Please use a pass-through query to access remote object '"RemoteDb"."dbo"."RemoteTable"'.

I have already setup the linked server [RemoteServer.dev.com].I was trying to perform an bulk insert from a remote table into the current table something like this -

INSERT INTO [CurrentDb].[dbo].[Mytable]
     (
       col1,
       col2
      )
 SELECT
  col1,col2
 FROM [RemoteServer.dev.com].[RemoteDb].[dbo].[RemoteTable]

Can anyone please help me out..thanks.

like image 266
Vishal Avatar asked Oct 05 '10 15:10

Vishal


People also ask

Why are linked server queries so bad?

If you run the same linked server query a dozen times – even if the rows aren't changing, even if the database is read-only, even if all twelve queries run at the same time, SQL Server makes a dozen different connections over to the linked server and fetches the data from scratch, every single freakin' time.

How do I select data from a linked server?

1 Open SQL Server Management Studio, navigate to the Object Explorer pane, and select Server Objects > Linked servers > Providers. 2 Right-click mrOledb. Provider and select Properties. 3 Select allow in process, and then click OK.


1 Answers

As the error indicates, you need a pass-through query here because of the datatypes. Try this:

INSERT INTO [CurrentDb].[dbo].[Mytable]
     (
       col1,
       col2
      )
    SELECT col1, col2 
        FROM OPENQUERY([RemoteServer.dev.com], 'SELECT col1, col2 FROM [RemoteDb].[dbo].[RemoteTable]')
like image 62
Joe Stefanelli Avatar answered Oct 08 '22 07:10

Joe Stefanelli