Skip to content

Commit d508b4a

Browse files
authored
fix: MSSQL login fails with "Unable to determine initial language" (#661) (#663)
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.
1 parent 7b18241 commit d508b4a

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Plugins/MSSQLDriverPlugin/CFreeTDS/include/sybdb.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ typedef struct loginrec LOGINREC;
4444
#define SYBDATETIMN 111
4545
#define SYBUNIQUE 36
4646

47-
// Login property constants for dbsetlname() — values verified against FreeTDS 1.4 sybdb.h
48-
#define DBSETHOST 1
49-
#define DBSETUSER 2
50-
#define DBSETPWD 3
51-
#define DBSETAPP 5 // 4 is unused; real FreeTDS DBSETAPP = 5
52-
#define DBSETCHARSET 7 // Client charset for dbsetlname() — controls string encoding
47+
// Login property constants for dbsetlname() — values from FreeTDS master/include/sybdb.h
48+
#define DBSETHOST 1
49+
#define DBSETUSER 2
50+
#define DBSETPWD 3
51+
#define DBSETAPP 5
52+
#define DBSETBCP 6
53+
#define DBSETNATLANG 7
54+
#define DBSETCHARSET 10
55+
#define DBSETPACKET 11
56+
#define DBSETENCRYPT 12
57+
#define DBSETDBNAME 14
5358

5459
// Convenience macros (match FreeTDS sybdb.h)
5560
#define DBSETLHOST(x, y) dbsetlname((x), (y), DBSETHOST)

Plugins/MSSQLDriverPlugin/MSSQLPlugin.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ private final class FreeTDSConnection: @unchecked Sendable {
196196
_ = dbsetlname(login, user, Int32(DBSETUSER))
197197
_ = dbsetlname(login, password, Int32(DBSETPWD))
198198
_ = dbsetlname(login, "TablePro", Int32(DBSETAPP))
199+
_ = dbsetlname(login, "us_english", Int32(DBSETNATLANG))
199200
_ = dbsetlname(login, "UTF-8", Int32(DBSETCHARSET))
200201
_ = dbsetlversion(login, UInt8(DBVERSION_74))
201202

0 commit comments

Comments
 (0)