我正在使用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.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|