Wide varchar field causes “Requested conversion is not supported” error using openquery with MySQL linked server

允我心安 提交于 2019-12-01 20:37:20

In my testing, I found that adding CAST(field as char(4000)) also solved the problem.

I created the following in a MySQL 5.1 database:

create table tmp_patrick (summary_text varchar(4096));
insert into tmp_patrick values ('foo');

When I executed the following on SQL Server 2008 R2 SP1 (10.50.2500), using MySQL ODBC driver 64-bit, either version 5.1 or 5.2w:

select * from openquery(MYSQL, 'select summary_text from scratch.tmp_patrick')

it generates the error:

OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "Requested conversion is not supported.".
Msg 7341, Level 16, State 2, Line 1
Cannot get the current row value of column "[MSDASQL].summary_text" from OLE DB provider "MSDASQL" for linked server "MYSQL". 

but if I add CAST:

select * from openquery(MYSQL, 'select CAST(summary_text as char(4000)) from scratch.tmp_patrick')

then it works. Casting to char(4001) will fail.

It's not clear to me where the 4000 character limit comes from.

I managed to fix this issue by changing the datatype to TEXT at both MySql and MSSQL side.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!