You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: support (localdb)\instance server names on Windows - #816
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):
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.
Fixesmicrosoft#470
-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.
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
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
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.
Fixes #470
sqlcmd -S (localdb)\MSSQLLocalDBfailed withno named pipe instance matching 'MSSQLLOCALDB' returned from host '(localdb)'because(localdb)was treated as a host name.Changes
splitServerrecognizes(localdb),(localdb)\instanceand(localdb)\.\sharedinstance(case-insensitive).ConnectionStringresolves LocalDB names to the instance's named pipe (\.\pipe\LOCALDB#xxxxxxxx\tsql\query) and connects withnp.(localdb)alone usesMSSQLLocalDB; combining it withtcp:/lpc:returnsInvalidServerName.--server-nameoverride is skipped for LocalDB, as for other named pipe connections.LocalDBStartInstanceinSqlUserInstance.dll, located viaHKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\<newest>\InstanceAPIPath. This starts the instance if needed and creates the automaticMSSQLLocalDBinstance, matching ODBC sqlcmd. Errors useLocalDBFormatMessage, e.g.Unable to start LocalDB instance nope: The specified LocalDB instance does not exist.LocalDB is only supported on Windows.go generatealso picked up a few upstream strings that were missing from the catalog.Testing
TestResolveLocalDBPipestarts the real default instance on Windows and is skipped when LocalDB isn't installed.sqlcmd -S (localdb)\MSSQLLocalDB -E -Q "select @@servername"returns<machine>\LOCALDB#6EAC2BFCsqlcmd -S (localdb) -Q "select db_name()"returnsmastersqlcmd -S (LocalDB)\nope -E -Q "select 1"prints the LocalDB error and exits 1Shared instances (
(localdb)\.\Name) are passed to the LocalDB API as-is; not tested since no shared instance was available.