微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ADO无法使用本机客户端(SQLNCLI)访问SQL Server XML类型列

我正在使用ADO和一个“本机”驱动程序(例如sqlNCLI,sqlNCLI10,sqlNCLI11)连接到sql Server(而不是旧的sqlOLEDB驱动程序).

ADO不了解本机驱动程序公开的XML sql Server数据类型:

field: ADOField;

field := recordset.Fields.Items["SomeXmlColumn"];

尝试访问field.Value会抛出EOleException:

>来源:Microsoft Cursor Engine
> ErrorCode:0x80040E21(E_ITF_0E21)
>消息:多步操作生成错误.检查每个状态值

本机客户端驱动程序(例如sqlNCLI,sqlNCLI11)将ADO的Xml数据类型呈现为

field.Type_ = 141 //???

旧版sqlOLEDB驱动程序将ADO的Xml数据类型显示adLongVarWChar,即unicode字符串:

field.Type_ = 203 //adLongVarWChar

字段中包含的VARIANT值.值是WideString (technically known as a BSTR)

tvarData(field.Value).vtype = 8 //VT_BSTR

在我看来,这是ADO(Windows 7 SP1)中的一个错误,而不是我可以解决的问题.

我该如何解决

奖金阅读

> Delphi with SQL Server: OLEDB vs. Native Client drivers

解决方法

MSDN documentation

To enable ADO to use new features of recent versions of sql Server,
some enhancements have been made to the sql Server Native Client OLE
DB provider which extends the core features of OLE DB. These
enhancements allow ADO applications to use newer sql Server features
and to consume two data types introduced in sql Server 2005: xml and
udt. These enhancements also exploit enhancements to the varchar,
nvarchar,and varbinary data types. sql Server Native Client adds the
sspROP_INIT_DATATYPECOMPATIBILITY initialization property to the
DBPROPSET_sqlSERVERDBINIT property set for use by ADO applications so
that the new data types are exposed in a way compatible with ADO. In
addition,the sql Server Native Client OLE DB provider also defines a
new connection string keyword named DataTypeCompatibility that is set
in the connection string.

因此,要在Native Client中启用新的sql Server功能,您需要在连接字符串中添加以下关键字:

Provider=sqlNCLI11
DataTypeCompatibility=80

其中DataTypeCompatibility

Specifies the mode of data type handling to use. Recognized values are “0” for provider data types and “80” for sql Server 2000 data types.

原文地址:https://www.jb51.cc/mssql/76734.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐