Skip to content

SQLServerException provides null SQLState and 0 error code #2015

@labkey-adam

Description

@labkey-adam

Driver version

12.1.0.jre11-preview

SQL Server version

Microsoft SQL Server 2022 (RC1) - 16.0.950.9 (X64)

Client Operating System

Windows 10

JAVA/JVM version

OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (build 17.0.5+8, mixed mode, sharing)

Table schema

N/A

Problem description

SQLExceptions thrown by the 12.1.0 preview driver no longer include valid SQLState or error code values. This appears to be a significant regression since many applications rely on these values for proper exception handling. We happen to use Spring SQLExceptionTranslators to translate SQLExceptions into standard Spring runtime exceptions (DataIntegrityViolationException and DeadlockLoserDataAccessException in the below examples) and the translations are now failing because these return values are incorrect.

A couple examples that our test suite flagged are provided below, but this is likely not an exhaustive list.

Expected behavior

In previous versions (11.2.1, 10.2.1), calling getSQLState() returned a valid SQL state code and getErrorCode() returned a valid vendor code. Two examples:

  • Divide by zero ("com.microsoft.sqlserver.jdbc.SQLServerException: An error occurred during the current command (Done status 0). Divide by zero error encountered."):
    • e.getSQLState() returned "S0001"
    • e.getErrorCode() returned 8134
  • Deadlock loser ("com.microsoft.sqlserver.jdbc.SQLServerException: An error occurred during the current command (Done status 0). Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction."):
    • e.getSQLState() returned "40001"
    • e.getErrorCode() returned 1205

Actual behavior

With the preview driver, the above exceptions no longer provide valid values. In both cases:

  • e.getSQLState() returns null
  • e.getErrorCode() returns 0

Let me know if you need more information to resolve this.

Metadata

Metadata

Assignees

Labels

BugA bug in the driver. A high priority item that one can expect to be addressed quickly.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions