MSSQL Linked Server error: The OLE DB provider "OraOLEDB.Oracle" for linked server supplied inconsistent metadata for a column

MSSQL Linked Server error: The OLE DB provider "OraOLEDB.Oracle" for linked server supplied inconsistent metadata for a column

我试图使用链接服务器将数据从 Oracle 提取到 MSSqlserver 数据库。

select * from [LINK_NAME]..SCHEMA.TABLE;

但失败并出现以下错误:

The OLE DB provider "OraOLEDB.Oracle" for linked server "LINK_NAME" supplied inconsistent metadata for a column. The column "COLUMN_NAME" (compile-time ordinal 6) of object ""SCHEMA"."TABLE"" was reported to have a "LENGTH" of 100 at compile time and 200 at run time.

我还需要在 运行 时间在 where 条件下传递参数。我发现 OPENQUERY 作为解决方案,但它不支持 运行 时间的参数。

尝试使用 OPENQUERY 语法看看是否有帮助..

SELECT * FROM OPENQUERY(LINK_NAME, 'SELECT * FROM db.Schema.Table')

更多关于 OPENQUERY ...

我找到了解决方案:

错误是由于数据库列类型不匹配造成的。 ORACLE 使用 NVARCHAR 作为数据类型,但在 SQLSERVER 的情况下是 VARCHAR.

因为 NVARCHAR 的大小是 VARCHAR 的两倍,这就是它显示大小不匹配错误的原因。

将数据类型更改为相同对我有用。

我找到了 post 由 this blogger 编辑的解决方案。试试吧!

This tool from Sysinternals/Mark Russinovich is the best, and my only regret that day was not launching it earlier instead of scouring Google and going insane. I’ve limited Procmon to just sqlservr.exe, as it’s the SQL Service itself that loads/handles the providers and not the ssms.exe. Also of note is that the sqlservr.exe is a 64bit process while the management studio is still just 32bit. As the server service is loading the provider, and the service process is 64bit, the provider must also be available in 64 bit format.

The ODAC112021Xcopy_x64.zip was installed to C:\Oracle. What Procmon showed me however is that sqlservr is attempting to find the oci.dll in any folder but his! (It iterates through the %Path% sysvariable). When it finally gives up on find the dll, the SQL Service is in a unstable shape and the only way to stop the service was to kill it via taskmgr/procexp. Clearly I can see that the “xcopy” deployment – while not giving me any error messages – it also did not set the PATH variable! And this is what this post is really about… adding C:\Oracle and C:\Oracle\Bin to the Path variable or maybe it’s about employing investigative tools earlier in the process instead of relying on your search engine skills.

sqlservr.exe can now find the relevant DLL’s. The OCI.DLL in the root and the OraOLEDB11.DLL in the Bin subfolder. At this point I could query the database! If you did my steps as above and you still get the same error, I strongly suggest using Procmon.exe as I have instead of jumping to the next search result.

完整 post 是 here,包含更多详细信息。