fix(plugin-mssql): send database in login packet so DB-scoped logins connect#1558
Merged
datlechin merged 3 commits intoJun 2, 2026
Merged
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA. |
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Connecting to an Azure SQL Database fails with
Login failed for user '...'(SQL Server error 18456) when the login can only reach a single database, for example an Azure SQL contained user. The same credentials work in DBeaver and other clients.The driver set every login property except the database, connected, then ran
USE [database]:A login scoped to one database has no rights in
master, sodbopenis rejected beforeUSEever runs. Microsoft's own driver (and DBeaver, via JDBC) avoid this by putting the database in the login packet, the same as an ODBCDatabase=/Initial Catalog.Fix
Set the database on the login record with
DBSETDBNAMEbeforedbopen, so FreeTDS sends it in the LOGIN7 packet and the server authenticates directly against it. The post-connectdbuseis removed: it is the exact step that cannot work for a scoped login, and it is redundant once the database is in the login packet.switchDatabase()keeps usingdbuse, which is correct for an already authenticated session.This is more correct for every SQL Server, not just Azure, and matches what the official drivers do.
How it was diagnosed
Reproduced through the same FreeTDS library (pymssql) against a live Azure SQL server: login with the database in the packet succeeds, login without it fails with the identical 18456. The macOS unified log showed
FreeTDS msg 18456 sev 14from the plugin at thedbopenstage.Tests
Extracted the login parameter assembly into
MSSQLLoginParameters, a pure builder with no FreeTDS dependency, and addedMSSQLLoginParametersTests: the database is included when set, omitted when blank, and the credentials and encryption flag carry through.FreeTDSConnectionmaps each field to itsDBSET*constant.Checklist
CHANGELOG.mdupdated under[Unreleased]docs/databases/mssql.mdx)