问题
I want to use Always Encrypted
feature introduce in SQL Server 2016 SP1
. In order to do that, I need to use the new ODBC Driver 13.1 for SQL Server
instead the current one sqloledb
.
It seems it is breaking my application, for example, when XML
is returned. Here, it is said that:
In order to take advantage of new features introduced in SQL Server 2005 such as multiple active result sets (MARS), query notifications, user-defined types (UDTs), or the new xml data type, existing applications that use ActiveX Data Objects (ADO) should use the SQL Server Native Client OLE DB provider as their data access provider.
So, that's this mean that I need to rewrite code, where XML
is used?
I know that, Microsoft undeprecated the deprecated sqloledb
driver, but its first version coming in March 2018 will not support Always Encrypted
- so, I do not want to wait.
回答1:
Classic ADO has no notion of the SQL Server XML type. The legacy SQLOLEDB provider and legacy SQL Server ODBC driver return type adLongVarWChar (203) for XML so it's a string on the client side.
The newer SQL Server Native Client OLE DB provider returns type 141 for XML to ADO but there's no matching ADO DataTypeEnum (https://docs.microsoft.com/en-us/sql/ado/reference/ado-api/datatypeenum). The provider will return XML data as adLongVarWChar when the DataTypeCompatibility=80 connection string keyword is specified for ADO compatibility.
Unfortunately, there is no equivalent DataTypeCompatibility connection string keyword for ODBC drivers. The newer ODBC drivers return XML data as ADO type adLongVarBinary (205) when accessed via the MSDASQL provider classic ADO uses for ODBC drivers. So the XML will need to either be cast to/from nvarchar(MAX) in SQL queries or the adLongVarBinary value converted on the client side.
I can't say if the yet unreleased Microsoft OLE DB Driver for SQL Server will provide relief by supporting the DataTypeCompatibility keyword but I hope it does, similarly to Native Client. Hopefully, we'll know more details soon. I doubt ADO will be beefed up to support the newer SQL types natively since it's hardly been touched in the last 15 years but I've been wrong before.
来源:https://stackoverflow.com/questions/48660899/switching-from-sqloledb-to-odbc-driver-13-for-sql-server