Skip to content

useBulkCopyForBatchInsert : no ouput / slower / error #2527

Open
@JDBC-0

Description

@JDBC-0

Driver version

12.8.1

SQL Server version

Microsoft SQL Server 2019 (RTM-CU28-GDR) (KB5042749) - 15.0.4390.2 (X64) Aug 12 2024 13:08:42 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

Client Operating System

Windows 10 Pro

JAVA/JVM version

21.0.4

Problem description

After we adjusted some tables from DATETIME to DATETIME2, changed all our prepared stored procedures to prepared INSERT statements, following all restrictions in "Known limitations" (https://learn.microsoft.com/en-us/sql/connect/jdbc/use-bulk-copy-api-batch-insert-operation?view=sql-server-ver16#known-limitations) and switching URL parameter "useBulkCopyForBatchInsert" between true and false, we don't see any effect of this parameter!

Expected behavior

Batch INSERTs are faster with useBulkCopyForBatchInsert=true or info/warning message is logged if driver falls back to default batch INSERTs. As "Known Limitations" saiys:

"If the query fails because of errors unrelated to the SQL Server instance, the driver logs the error message and falls back to the original logic for batch insert."

Actual behavior

"errorCode=4022, message=Massenladedaten wurden erwartet, aber nicht gesendet. Der Batch wird beendet., SQLState=S0001, cause=null"
(4022: Bulk load data was expected but not sent. The batch will be terminated.)

Switching back to useBulkCopyForBatchInsert=false, no error occurs.

The problem interferes with #1784 (Bulk copy: fails with combination sendStringParametersAsUnicode=false). Also setting sendStringParametersAsUnicode=true , this error does not occur.

With
sendStringParametersAsUnicode=true;useBulkCopyForBatchInsert=true;sendTemporalDataTypesAsStringForBulkCopy=true
no error occurs, but the repeated test runs are SLOWER!

To avoid unexpected errors, we want to stay with sendStringParametersAsUnicode=false , but this causes the error above.

If we then set sendTemporalDataTypesAsStringForBulkCopy=false , the error occurs again.

We have no idea what other parameters in which combinations are required/necessary for bulk insert to work. We nocied that noo error occurs when alle 3 parameters

sendStringParametersAsUnicode=true;useBulkCopyForBatchInsert=true;sendTemporalDataTypesAsStringForBulkCopy=true

are either all "false" or either all "true". None of them show any performance improvements.

Any other details that can be helpful

JDBC URL: jdbc:sqlserver://{DBSERVERADR};databaseName=myDB;applicationName=myServer-{HOSTID};workstationID={HOSTID};integratedSecurity=true;sendStringParametersAsUnicode=false;encrypt=false;useBulkCopyForBatchInsert=true;sendTemporalDataTypesAsStringForBulkCopy=false

The mass INSERTs are done on connections with autocommit OFF and committing after each executeBatch().

Metadata

Metadata

Assignees

No one assigned

    Labels

    BacklogThe topic in question has been recognized and added to development backlog

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions