Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OLE DB provider 'for linked server returned data that does not match expected data length for

I get an error querying a remote postgresql server from my sql server 2017 Standard via a linked server

this is the query:

    SELECT CAST(test AS VARCHAR(MAX))  FROM  OpenQuery(xxxx, 
     'SELECT  corpo::TEXT as test From public.notification')

and this is the error message:

    Msg 7347, Level 16, State 1, Line 57
    OLE DB provider 'MSDASQL' for linked server 'xxx' returned data that                 does not match expected data length for 
    column '[MSDASQL].test'. The (maximum) expected data length is 1024,         while the returned data length is 7774.

Even without conversions the error stills

For the odbc and linked server I followed this handy guide.

like image 266
Gabriele D'Onufrio Avatar asked Jun 20 '19 10:06

Gabriele D'Onufrio


2 Answers

In my case, I was reading the data through a view. Apparently, the data size of one column was changed in the underlying table but the view still reported to the linked server the original smaller size of the column. The solution was to open the view with MSSMS and save it again.

like image 166
Dimitris Tsitsamis Avatar answered Sep 23 '22 19:09

Dimitris Tsitsamis


Can you try this?

SELECT  *
FROM    OPENQUERY(xxxx, '\
SELECT  TRIM(corpo) AS test
FROM    public.notification;
') AS oq
  1. I prefer using OPENQUERY since it will send the exact query to the linked server for it to execute.
  2. MySQL currently has problem with casting to VARCHAR data type, so I using TRIM() function to cheat it.
like image 32
Đức Trí Bùi Avatar answered Sep 23 '22 19:09

Đức Trí Bùi