Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: Only 65,534 rows are inserted when you try to insert more than 65,535 records in a SQL Server table by using the SQLBulkOperations ODBC function


View products that this article applies to.

Symptoms

When you use the SQLBulkOperations Open Database Connectivity (ODBC) function to insert more than 65,535 records in a Microsoft SQL Server table, the SQLBulkOperations function inserts only 65,534 records in the SQL Server table. You may receive the following error message:
[HY000] [0]
[Microsoft][ODBC SQL Server Driver]Unspecified error occurred on SQL Server. Connection may have been terminated by the server.
An error message that is similar to the following may also be logged in the SQL Server error log file:
2004-07-19 21:13:35.86 spid52 Error: 17805, Severity: 20, State: 3
2004-07-19 21:13:35.86 spid52 Invalid buffer received from client.
Note This problem occurs on computers that are running the 32-bit version of Microsoft Windows.

↑ Back to the top


Cause

On computers that are running the 32-bit version of Windows, the SQLSetPos function is invoked by the SQLBulkOperations function. The SQLSetPos function internally converts the SQL_ATTR_ROW_ARRAY_SIZE attribute from the UDWORD data type to the SQLUSMALLINT data type.

The value that can be stored in the SQLUSMALLINT data type ranges from 0 to 65,535. Therefore, if the value of the SQL_ATTR_ROW_ARRAY_SIZE attribute is more than 65,535, the data type conversion truncates the data in the SQL_ATTR_ROW_ARRAY_SIZE attribute.

Note The SQL_ATTR_ROW_ARRAY_SIZE attribute indicates the number of rows that you want to insert in the SQL Server table.

↑ Back to the top


Workaround

To work around this problem, do not insert more than 65,535 records in the SQL Server table by using the SQLBulkOperations function. To insert more than 65,535 records in a SQL Server table, you must run the SQLBulkOperations functions several times.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

↑ Back to the top


More information

On a computer that is running the 64-bit version of Windows, the SQLSETPOSIROW data type is equal to the SQLULEN data type, and the data type of the SQL_ATTR_ROW_ARRAY_SIZE attribute is equal to SQLULEN. Therefore, in the SQLSetPos function, the type conversion of the SQL_ATTR_ROW_ARRAY_SIZE attribute to the SQLSETPOSIROW data type does not cause any data loss. Therefore, the SQLBulkOperations function runs successfully on a computer that is running the 64-bit version of Windows.

Note The SQLBulkOperations function has no relationship to the SQL Server bulk copy functions. Applications must use the SQL Server-specific bulk copy functions to perform bulk copy operations.

↑ Back to the top


Keywords: KB875411, kbbug, kbtshoot, kberrmsg, kbtable, kbfunctions

↑ Back to the top

Article Info
Article ID : 875411
Revision : 4
Created on : 7/22/2004
Published on : 7/22/2004
Exists online : False
Views : 373