OLE DB 提供程序 'MSDASQL' 为列提供的元数据不一致。执行时更改了元数据信息。(连的MYSQL)
在SQL下连过MYSQL数据库啊,我连上了,我查询
select uid from mysqllinkserver...user1
提示这个错误:
务器: 消息 7356,级别 16,状态 1,行 1
OLE DB 提供程序 'MSDASQL' 为列提供的元数据不一致。执行时更改了元数据信息。
OLE DB 错误跟踪[Non-interface error: Column 'user_name' (compile-time ordinal 2) of object 'user1' was reported to have a LENGTH of 5 at compile time and 21 at run time]。
这样查询可以:把变量换成具体值就可以,
select * from OPENQUERY(济南网通, 'select uid from user1' where mob=@mobile),但是openquery不支持变量
有方法解决吗,这里必须要用变量
[解决办法]
用动态语句试试
set quoted_identifier off
declare @sql nvarchar(1000),@mobile nvarchar(10)
set @mobile='243345'
set @sql="select * from OPENQUERY([xxbb\xxbba],'select uid from 库名.dbo.user1 where mob=''"+@mobile+"''')"
exec sp_executesql @sql
set quoted_identifier on