Skip to content

fix: MSSQL login fails with "Unable to determine initial language" (#661)#663

Merged
datlechin merged 1 commit intomainfrom
fix/mssql-login-language
Apr 10, 2026
Merged

fix: MSSQL login fails with "Unable to determine initial language" (#661)#663
datlechin merged 1 commit intomainfrom
fix/mssql-login-language

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Summary

Fix MSSQL connection failing with "Login failed for user 'sa'" when SQL Server requires language in the TDS login packet (common with Docker images).

Closes #661

Root Cause

The C bridge header (CFreeTDS/include/sybdb.h) had wrong constant values for dbsetlname():

Constant Our value (wrong) Real FreeTDS
DBSETCHARSET 7 10
DBSETNATLANG (missing) 7

So dbsetlname(login, "UTF-8", 7) was actually setting the language to "UTF-8" (not charset), causing SQL Server error state 17: "Unable to determine the initial language and date format."

Fix

  1. Corrected all constants in sybdb.h to match FreeTDS master/include/sybdb.h
  2. Added DBSETNATLANG=7 with "us_english" to the login packet
  3. DBSETCHARSET=10 now correctly sets UTF-8 charset

Test plan

  • Docker MSSQL 2022: connection succeeds (was failing with state 17)
  • Verify existing MSSQL connections still work
  • Verify charset handling (special characters in queries/results)

)

Root cause: C bridge header had wrong FreeTDS constant values.
DBSETCHARSET was 7 (actually DBSETNATLANG), DBSETCHARSET is 10.
So "UTF-8" was being sent as the language, and no charset was set.

Fix: correct all dbsetlname constants to match FreeTDS master/include/sybdb.h,
add DBSETNATLANG=7 with "us_english" to the login packet.
@datlechin datlechin merged commit d508b4a into main Apr 10, 2026
2 checks passed
@datlechin datlechin deleted the fix/mssql-login-language branch April 10, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSSQL connection failed

1 participant