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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/mssql/76734.html

猜你在找的MsSQL相关文章