Skip to content

feat: support (localdb)\instance server names on Windows - #816

Open
Arthur Stankevich (a-stankevich) wants to merge 2 commits into
microsoft:mainfrom
a-stankevich:feat/localdb-support
Open

Arthur Stankevich (a-stankevich) wants to merge 2 commits into
microsoft:mainfrom
a-stankevich:feat/localdb-support

Conversation

@a-stankevich

Copy link
Copy Markdown

Fixes #470

sqlcmd -S (localdb)\MSSQLLocalDB failed with no named pipe instance matching 'MSSQLLOCALDB' returned from host '(localdb)' because (localdb) was treated as a host name.

Changes

  • splitServer recognizes (localdb), (localdb)\instance and (localdb)\.\sharedinstance (case-insensitive).
  • ConnectionString resolves LocalDB names to the instance's named pipe (\.\pipe\LOCALDB#xxxxxxxx\tsql\query) and connects with np. (localdb) alone uses MSSQLLocalDB; combining it with tcp:/lpc: returns InvalidServerName. --server-name override is skipped for LocalDB, as for other named pipe connections.
  • On Windows the pipe comes from LocalDBStartInstance in SqlUserInstance.dll, located via HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\<newest>\InstanceAPIPath. This starts the instance if needed and creates the automatic MSSQLLocalDB instance, matching ODBC sqlcmd. Errors use LocalDBFormatMessage, e.g. Unable to start LocalDB instance nope: The specified LocalDB instance does not exist.
  • Other platforms return LocalDB is only supported on Windows.
  • README note and regenerated translation catalog. Running go generate also picked up a few upstream strings that were missing from the catalog.

Testing

  • Unit tests for name parsing, connection string construction and version ordering.
  • TestResolveLocalDBPipe starts the real default instance on Windows and is skipped when LocalDB isn't installed.
  • Manually on Windows 11 with LocalDB 2019 (15.0.4382):
    • sqlcmd -S (localdb)\MSSQLLocalDB -E -Q "select @@servername" returns <machine>\LOCALDB#6EAC2BFC
    • sqlcmd -S (localdb) -Q "select db_name()" returns master
    • sqlcmd -S (LocalDB)\nope -E -Q "select 1" prints the LocalDB error and exits 1
  • Builds for windows/amd64, windows/arm64, linux and darwin. golangci-lint reports nothing new in the changed files.

Shared instances ((localdb)\.\Name) are passed to the LocalDB API as-is; not tested since no shared instance was available.

Resolve (localdb)\<instance> to the instance's named pipe through the
LocalDB instance API (SqlUserInstance.dll), starting the instance and
creating the automatic MSSQLLocalDB instance when needed. (localdb)
without an instance uses MSSQLLocalDB. Other platforms report that
LocalDB is only supported on Windows.

Fixes microsoft#470
Copilot AI balanced review requested due to automatic review settings October 14, 2026 09:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Dedicated-admin mode produces an incompatible LocalDB protocol, and the non-Windows error is missing from localization catalogs.

2 open findings
What changed in this PR

Adds SQL Server Express LocalDB support, resolving (localdb) server names to Windows named pipes.

Changes:

  • Parses LocalDB server names and constructs named-pipe connection strings.
  • Uses the Windows LocalDB API to start instances and format errors.
  • Adds documentation, tests, and regenerated localization catalogs.
File Description
README.md Documents LocalDB usage.
pkg/​sqlcmd/​util.go Parses LocalDB server names.
pkg/​sqlcmd/​localdb.go Defines shared LocalDB resolution logic.
pkg/​sqlcmd/​localdb_windows.go Implements Windows LocalDB API integration.
pkg/​sqlcmd/​localdb_windows_test.go Tests Windows resolution and version ordering.
pkg/​sqlcmd/​localdb_test.go Tests parsing and connection strings.
pkg/​sqlcmd/​localdb_other.go Returns the unsupported-platform error.
pkg/​sqlcmd/​connect.go Integrates LocalDB named pipes into connections.
internal/​translations/​catalog.go Regenerates the translation catalog.
internal/​translations/​locales/​de-DE/​out.gotext.json Updates German message metadata.
internal/​translations/​locales/​en-US/​out.gotext.json Updates English message metadata.
internal/​translations/​locales/​es-ES/​out.gotext.json Updates Spanish message metadata.
internal/​translations/​locales/​fr-FR/​out.gotext.json Updates French message metadata.
internal/​translations/​locales/​it-IT/​out.gotext.json Updates Italian message metadata.
internal/​translations/​locales/​ja-JP/​out.gotext.json Updates Japanese message metadata.
internal/​translations/​locales/​ko-KR/​out.gotext.json Updates Korean message metadata.
internal/​translations/​locales/​pt-BR/​out.gotext.json Updates Portuguese message metadata.
internal/​translations/​locales/​ru-RU/​out.gotext.json Updates Russian message metadata.
internal/​translations/​locales/​zh-CN/​out.gotext.json Updates Simplified Chinese metadata.
internal/​translations/​locales/​zh-TW/​out.gotext.json Updates Traditional Chinese metadata.
Files not reviewed (1)
  • internal/translations/catalog.go: Generated file

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/sqlcmd/connect.go Outdated
Comment thread pkg/sqlcmd/localdb_other.go Outdated
@a-stankevich

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

-A with a (localdb) server produced a LocalDB pipe with protocol=admin;
it now returns InvalidServerName like other non-named-pipe protocols.

The non-Windows "LocalDB is only supported on Windows" message lived in a
!windows file, so catalog extraction on Windows never saw it. The stub now
returns errors.ErrUnsupported and the shared resolver produces the
localized message.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

LocalDB connections cannot work on Windows non-amd64 builds because the named-pipe transport is registered only on amd64.

0 open findings

2 resolved since last review
Files not reviewed (1)
  • internal/translations/catalog.go: Generated file
Previously missed (1)

In code that hasn't changed since last review

Medium severity LocalDB forces unsupported named-pipe transport on Windows ARM64

pkg/​sqlcmd/​connect.go:118

This forces every Windows build onto the np transport, but that transport is registered only by sqlcmd_windows_amd64.go; the file explicitly excludes ARM because named pipes are unsupported there. Consequently the advertised Windows/arm64 build can resolve a LocalDB name and emit protocol=np, but the connector has no named-pipe parser and cannot connect. Either enable a working named-pipe implementation for the other Windows architectures, or gate LocalDB support to windows/amd64 and return/document an architecture-specific error.

🧠 Review effort: Balanced

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.

LocalDB connections

2 participants