Skip to content

.NET 5.0 | Implement SqlException.SqlState #648

Description

@roji

dotnet/runtime#35601 introduces DbException.SqlState for .NET 5.0, for standard 5-character error codes.

SQL Server has its own incompatible numeric error code scheme, currently surfaced via SqlError.Number. However, the SQL Server ODBC driver apparently maps the native SQL Server errors to SQLSTATE values. As pointed out by @cheenamalhotra, the JDBC driver does the same, although it maps only a handful of codes (maybe the ODBC translation could be copied?)

Activity

  1. cheenamalhotra commented on Jul 13, 2020

    @cheenamalhotra
    Member

    Thanks @roji

    Acknowledged for .NET 5.0 new APIs.

  2. changed the title [-]Implement SqlException.SqlState[/-] [+].NET 5.0 | Implement SqlException.SqlState[/+] on Jul 13, 2020
  3. asante07 commented on Jun 23, 2023

    @asante07

    10:14:55 AM [main] Initializing Control Panel
    10:14:55 AM [main] Windows Version: Enterprise 64-bit
    10:14:55 AM [main] XAMPP Version: 8.2.4
    10:14:55 AM [main] Control Panel Version: 3.3.0 [ Compiled: Apr 6th 2021 ]
    10:14:55 AM [main] You are not running with administrator rights! This will work for
    10:14:55 AM [main] most application stuff but whenever you do something with services
    10:14:55 AM [main] there will be a security dialogue or things will break! So think
    10:14:55 AM [main] about running this application with administrator rights!
    10:14:55 AM [main] XAMPP Installation Directory: "c:\xampp"
    10:14:55 AM [main] Checking for prerequisites
    10:15:29 AM [main] All prerequisites found
    10:15:29 AM [main] Initializing Modules
    10:15:29 AM [main] Starting Check-Timer
    10:15:29 AM [main] Control Panel Ready
    10:15:45 AM [mysql] Attempting to start MySQL app...
    10:15:47 AM [mysql] Status change detected: running
    10:15:52 AM [mysql] Status change detected: stopped
    10:15:52 AM [mysql] Error: MySQL shutdown unexpectedly.
    10:15:52 AM [mysql] This may be due to a blocked port, missing dependencies,
    10:15:52 AM [mysql] improper privileges, a crash, or a shutdown by another method.
    10:15:52 AM [mysql] Press the Logs button to view error logs and check
    10:15:52 AM [mysql] the Windows Event Viewer for more clues
    10:15:52 AM [mysql] If you need more help, copy and post this
    10:15:52 AM [mysql] entire log window on the forums
    10:16:33 AM [Apache] Attempting to start Apache app...
    10:16:34 AM [Apache] Status change detected: running

    Is there a way of finding out MySql Server error if the MySQL shutdown unexpectedly. I tried looking at event logs but don't understand how to fix the error. Very new to MySQL. Similar to implementation of SqlState!!? Thanks in advance.

  4. ErikEJ commented on Jun 23, 2023

    @ErikEJ
    Contributor

    @asante07 I think you are asking in the wrong place...

  5. moved this from To triage to Backlog in SqlClient Boardon Nov 21, 2025
  6. edwardneal commented on Sep 2, 2026

    @edwardneal
    Contributor

    The mssql-rs driver exposes a list of mappings; this matches the ODBC driver. The methodology is thus:

    1. Provide a hardcoded SQLSTATE in specific scenarios when no server error number is available - typically connection establishment.
    2. Look SqlError.Number up in this mapping table. If it matches, use that - if not, continue.
    3. Check SqlError.Class. If it's greater than 18, the SQLSTATE is HY000. If the class is greater than 10, the SQLSTATE is 42000. Otherwise, it's 01000.

    I've verified that steps 2 and 3 generate identical SQLSTATE values to the ODBC driver by connecting to a TDS server capable of issuing SQL errors with the correct number and class values.

  7. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions