从 SQL Server 2005 Native Client 更新应用程序Updating an Application from SQL Server 2005 Native Client

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database 是Azure SQL 托管实例Azure SQL Managed InstanceYesAzure SQL 托管实例Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是并行数据仓库Parallel Data Warehouseyes并行数据仓库Parallel Data Warehouse

本主题介绍自 SQL ServerSQL Server 中的 SQL ServerSQL Server Native Client 以来在 SQL Server 2005 (9.x)SQL Server 2005 (9.x) Native Client 中的重大更改。This topic discusses the breaking changes in SQL ServerSQL Server Native Client since SQL ServerSQL Server Native Client in SQL Server 2005 (9.x)SQL Server 2005 (9.x).

从 Microsoft 数据访问组件 (MDAC) 升级到 SQL ServerSQL Server Native Client 时,也会看到一些行为差异。When you upgrade from Microsoft Data Access Components (MDAC) to SQL ServerSQL Server Native Client, you might also see some behavior differences. 有关详细信息,请参阅 将应用程序更新为从 MDAC SQL Server Native ClientFor more information, see Updating an Application to SQL Server Native Client from MDAC.

SQL ServerSQL Server Native Client 9.0 随 SQL Server 2005 (9.x)SQL Server 2005 (9.x) 附带。Native Client 9.0 shipped with SQL Server 2005 (9.x)SQL Server 2005 (9.x). SQL ServerSQL Server Native Client 10.0 随 SQL Server 2008SQL Server 2008 附带。Native Client 10.0 shipped with SQL Server 2008SQL Server 2008. SQL ServerSQL Server Native Client 10.5 随 SQL Server 2008 R2SQL Server 2008 R2 附带。Native Client 10.5 shipped with SQL Server 2008 R2SQL Server 2008 R2. SQL ServerSQL Server Native Client 11.0 随 SQL Server 2012 (11.x)SQL Server 2012 (11.x)SQL Server 2014 (12.x)SQL Server 2014 (12.x) 附带。Native Client 11.0 shipped with SQL Server 2012 (11.x)SQL Server 2012 (11.x) and SQL Server 2014 (12.x)SQL Server 2014 (12.x).

SQL Server 2005 (9.x)SQL Server 2005 (9.x) 以来 SQL Server Native Client 中已更改的行为Changed behavior in SQL Server Native Client Since SQL Server 2005 (9.x)SQL Server 2005 (9.x) 说明Description
OLE DB 仅填充到定义的小数位数。OLE DB pads only to the defined scale. 对于将转换的数据发送到服务器的转换, SQL ServerSQL Server Native Client (从 SQL Server 2008SQL Server 2008) 填充数据中的尾随零到最大 日期时间 值的最大长度。For conversions where converted data is sent to the server, SQL ServerSQL Server Native Client (beginning in SQL Server 2008SQL Server 2008) pads trailing zeros in data only up to the maximum length of datetime values. SQL Server Native Client 9.0 则填充到 9 位数。SQL Server Native Client 9.0 padded to 9 digits.
验证 ICommandWithParameter::SetParameterInfo 的 DBTYPE_DBTIMESTAMP。Validate DBTYPE_DBTIMESTAMP for ICommandWithParameter::SetParameterInfo. SQL ServerSQL Server 本机客户端 (从 SQL Server 2008SQL Server 2008) 中开始实现对 ICommandWithParameter:: SetParameterInfo 中的 bScale 的 OLE DB 要求,将设置为 DBTYPE_DBTIMESTAMP 的秒小数部分。Native Client (beginning in SQL Server 2008SQL Server 2008) implements the OLE DB requirement for bScale in ICommandWithParameter::SetParameterInfo to be set to the fractional seconds' precision for DBTYPE_DBTIMESTAMP.
sp_columns 存储过程现在返回“否” ,而不是为 IS_NULLABLE 列返回“否” 。The sp_columns stored procedure now returns "NO" instead of "NO " for the IS_NULLABLE column. SQL ServerSQL Server Native Client 10.0 (SQL Server 2008SQL Server 2008) 开始, sp_columns 存储过程现在为 IS_NULLABLE 列返回 "no" ,而不是 "否"Beginning in SQL ServerSQL Server Native Client 10.0 (SQL Server 2008SQL Server 2008), sp_columns stored procedure now returns "NO" instead of "NO " for an IS_NULLABLE column.
SQLSetDescRec、SQLBindParameter 和 SQLBindCol 现在会执行一致性检查。SQLSetDescRec, SQLBindParameter, and SQLBindCol now perform consistency checking. SQL ServerSQL Server在 Native Client 10.0 之前,设置 SQL_DESC_DATA_PTR 不会对 SQLSetDescRec、SQLBindParameter 或 SQLBindCol 中的任何描述符类型进行一致性检查。Prior to SQL ServerSQL Server Native Client 10.0, setting SQL_DESC_DATA_PTR did not cause a consistency check for any descriptor type in SQLSetDescRec, SQLBindParameter, or SQLBindCol.
SQLCopyDesc 现在执行描述符一致性检查。SQLCopyDesc now does descriptor consistency checking. SQL ServerSQL Server Native Client 10.0 之前,当对特定记录设置 SQL_DESC_DATA_PTR 字段时,SQLCopyDesc 不执行一致性检查。Prior to SQL ServerSQL Server Native Client 10.0, SQLCopyDesc did not do a consistency check when the SQL_DESC_DATA_PTR field was set on a particular record.
SQLGetDescRec 不再执行描述符一致性检查。SQLGetDescRec no longer does a descriptor consistency check. SQL ServerSQL Server Native Client 10.0 之前,在设置 SQL_DESC_DATA_PTR 字段时,SQLGetDescRec 执行了描述符一致性检查。Prior to SQL ServerSQL Server Native Client 10.0, SQLGetDescRec performed a descriptor consistency check when the SQL_DESC_DATA_PTR field was set. 这不是 ODBC 规范和 SQL ServerSQL Server Native Client 10.0 (SQL Server 2008SQL Server 2008) 以及更高版本所要求的,该一致性检查不再执行。This was not required by the ODBC specification and in SQL ServerSQL Server Native Client 10.0 (SQL Server 2008SQL Server 2008) and later versions, this consistency check is no longer performed.
日期超出范围时返回其他错误。Different error returned when date is out of range. 对于 日期时间 类型, SQL ServerSQL Server Native Client (会从 SQL Server 2008SQL Server 2008 超出早期版本返回的超出范围的) 开始返回不同的错误号。For the datetime type, a different error number will be returned by SQL ServerSQL Server Native Client (beginning in SQL Server 2008SQL Server 2008) for an out-of-range date than was returned in earlier versions.

具体来说, SQL ServerSQL Server Native client 9.0 在字符串转换为 datetime 时,将所有超出范围的年份值返回22007,而 SQL ServerSQL Server native client 从版本) (10.0 开始, SQL Server 2008SQL Server 2008 当日期在 datetime2 支持的范围内但在日期 时间smalldatetime 支持的范围之外时,将返回22008。Specifically, SQL ServerSQL Server Native Client 9.0 returned 22007 for all out of range year values in string conversions to datetime, and SQL ServerSQL Server Native Client beginning with version 10.0 (SQL Server 2008SQL Server 2008) returns 22008 when the date is within the range supported by datetime2 but outside the range supported by datetime or smalldatetime.
如果舍入将更改日期,则 datetime 值将截断秒的小数部分,并且不舍入 。datetime value truncates fractional seconds and not round if rounding will change the day. SQL ServerSQL Server Native Client 10.0 之前,对于发送到服务器的 datetime 值的客户端行为是将它们舍入到最接近 1/300 秒的值 。Prior to SQL ServerSQL Server Native Client 10.0, the client behavior for datetime values sent to the server is to round them to nearest 1/300th of a second. SQL ServerSQL Server Native Client 10.0 开始,如果舍入会更改日期,则该方案会导致截断秒的小数部分。Beginning in SQL ServerSQL Server Native Client 10.0, this scenario causes a truncation of fractional seconds if rounding changes the day.
datetime 值的可能截断秒。Possible trunction of seconds for datetime value. 如果您绑定到某一 datetime 列并且其类型标识符为 DBTYPE_DBTIMESTAMP (OLE DB) 或 SQL_TIMESTAMP (ODBC)、小数位数为 0,则使用连接到 SQL Server 2008SQL Server 2008 2005 服务器的 SQL ServerSQL Server Native Client(或更高版本)生成的应用程序将截断要发送到服务器的时间部分中的秒和秒的小数部分。An application built with SQL Server 2008SQL Server 2008 Native Client (or later) that connects to a SQL ServerSQL Server 2005 server will truncate seconds and fractional seconds for time portion of data sent to the server if you bind to a datetime column with a type identifier of DBTYPE_DBTIMESTAMP (OLE DB) or SQL_TIMESTAMP (ODBC) and a scale of 0.

例如:For example:

输入数据:1994-08-21 21:21:36.000Input data: 1994-08-21 21:21:36.000

插入的数据:1994-08-21 21:21:00.000Inserted data: 1994-08-21 21:21:00.000
从 DBTYPE_DBTIME 到 DBTYPE_DATE 的 OLE DB 数据转换不会再导致日期发生更改。OLE DB data conversion from DBTYPE_DBTIME to DBTYPE_DATE no longer can cause the day to change. SQL ServerSQL Server Native Client 10.0 之前,如果 DBTYPE_DATE 的时间部分是在距离午夜的半秒内,则 OLE DB 转换代码将导致日期发生更改。Prior to SQL ServerSQL Server Native Client 10.0, if the time part of a DBTYPE_DATE was within a half second of midnight, OLE DB conversion code caused the day to change. SQL ServerSQL Server Native Client 10.0 开始,日期不会更改(秒的小数部分将截断但不舍入)。Beginning in SQL ServerSQL Server Native Client 10.0, the day will not change (fractional seconds are truncated and not rounded).
IBCPSession::BCColFmt 转换更改。IBCPSession::BCColFmt conversion changes. SQL ServerSQL Server Native Client 10.0 开始,当你使用 IBCPSession:: BCOColFmt 将 SQLDATETIME 或 SQLDATETIME 转换为字符串类型时,将导出小数值。Beginning in SQL ServerSQL Server Native Client 10.0, when you use IBCPSession::BCOColFmt to convert SQLDATETIME or SQLDATETIME to a string type, a fractional value is exported. 例如,将类型 SQLDATETIME 转换为类型 SQLNVARCHARMAX 时,SQL ServerSQL Server Native Client 的更早版本返回For example, when converting type SQLDATETIME to type SQLNVARCHARMAX, earlier versions of SQL ServerSQL Server Native Client returned

1989-02-01 00:00:00。1989-02-01 00:00:00. SQL ServerSQL Server Native Client 10.0 及更高版本返回 1989-02-01 00:00:00.0000000。Native Client 10.0 and later versions return 1989-02-01 00:00:00.0000000.
发送的数据的大小必须与 SQL_LEN_DATA_AT_EXEC 中指定的长度匹配。Size of data sent must match length specified in SQL_LEN_DATA_AT_EXEC. 使用 SQL_LEN_DATA_AT_EXEC 时,数据的大小必须与用 SQL_LEN_DATA_AT_EXEC 指定的长度匹配。When using SQL_LEN_DATA_AT_EXEC, the size of the data must match the length that you specified with SQL_LEN_DATA_AT_EXEC. 可以使用 SQL_DATA_AT_EXEC,但使用 SQL_LEN_DATA_AT_EXEC 有潜在的性能好处。You can use SQL_DATA_AT_EXEC but there are potential performance benefits to using SQL_LEN_DATA_AT_EXEC.
使用 BCP API 的自定义应用程序现在可以看到警告。Custom applications that use the BCP API can now see a warning. 对于所有类型,如果数据长度超过某字段的指定长度,则 BCP API 将生成警告消息。The BCP API will generate a warning message if data length is greater than the specified length for a field for all types. 以前,该警告仅针对字符类型,而不会针对所有类型发出。Previously, this warning was only given for character types, but will not be issued for all types.
将空字符串插入到绑定为日期/时间类型的 sql_variant 中会生成错误 。Inserting an empty string into a sql_variant bound as a date/time type generates an error. SQL ServerSQL Server Native Client 9.0 中,将空字符串插入到绑定为日期/时间类型的 sql_variant 中不会生成错误 。In SQL ServerSQL Server Native Client 9.0, inserting an empty string into a sql_variant bound as a date/time type did not generate an error. SQL ServerSQL Server Native Client 10.0(和更高版本)在这种情况下则会正确地生成错误。Native Client 10.0 (and later) correctly generates an error in this situation.
更严格的 SQL_C_TYPE _TIMESTAMP 和 DBTYPE_DBTIMESTAMP 参数验证。Stricter SQL_C_TYPE _TIMESTAMP and DBTYPE_DBTIMESTAMP parameter validation. SQL Server 2008SQL Server 2008 Native Client 之前,会将 datetime 值舍入,以适合 datetimesmalldatetime 列的小数位数 SQL ServerSQL ServerPrior to SQL Server 2008SQL Server 2008 Native Client, datetime values were rounded to fit the scale of datetime and smalldatetime columns by SQL ServerSQL Server. SQL Server 2008SQL Server 2008 Native Client(和更高版本)现在应用在 ODBC 核心规范中为秒的小数部分定义的更严格的验证规则。Native Client (and later) applies the stricter validation rules that are defined in the ODBC core specification for fractional seconds. 如果无法通过使用由客户端绑定所指定或暗含的小数位数在不截断尾随数字的情况下将参数值转换到 SQL 类型,则返回错误。If a parameter value cannot be converted to the SQL type by using the scale specified or implied by the client binding without truncation of trailing digits, an error is returned.
当有触发器运行时,SQL ServerSQL Server 可能会返回不同的结果。SQL ServerSQL Server might return different results when a trigger runs. SQL Server 2008SQL Server 2008 中引入的变化可能会导致应用程序得到从 NOCOUNT OFF 有效时导致触发器运行的语句返回的不同的结果 。Changes introduced in SQL Server 2008SQL Server 2008 might cause an application to have different results returned from a statement that caused a trigger to run when NOCOUNT OFF was in effect. 在这种情况下,您的应用程序可能会生成错误。In this situation, your application might generate an error. 若要解决此错误,请在触发器中设置 NOCOUNT ,或调用 SQLMoreResults 来前进到下一个结果。To resolve this error, set NOCOUNT ON in the trigger or call SQLMoreResults to advance to the next result.

另请参阅See Also

SQL Server Native Client 编程SQL Server Native Client Programming