Skip to content

Added support for Default connection (#18912) #19870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

yorek
Copy link
Member

@yorek yorek commented Aug 2, 2025

Description

Added support for a workspace default connection as requested in #18912. The default connection is saved in the defaultConnectionName setting:

{
    "mssql.defaultConnectionName": "YourConnectionProfileName"
}

Instead of specifying server name and database (as proposed in the related issue) the setting expect to have the name of the connection profile that should be used as default connection, to make it coherent with the overall connection behavior.

Code Changes Checklist

  • New or updated unit tests added
  • All existing tests pass (npm run test)
  • Code follows contributing guidelines
  • Telemetry/logging updated if relevant
  • No regressions or UX breakage

Reviewers: Please read our reviewer guidelines

@sggoose
Copy link
Contributor

sggoose commented Aug 4, 2025

Been hoping this could be a feature! Would you be able to modify this to always set the default connection to the last manually connected profile in a workspace? This would most accurately reflect the default connection behavior of SSMS in my opinion.

@yorek
Copy link
Member Author

yorek commented Aug 4, 2025

Been hoping this could be a feature! Would you be able to modify this to always set the default connection to the last manually connected profile in a workspace? This would most accurately reflect the default connection behavior of SSMS in my opinion.

That could be set as an option that can be turned on or off. Together with a right-click menu on a connection to make it as default. Let's have this first improvement done and then we can do this other two in the next, so that we move swiftly forward

@yorek
Copy link
Member Author

yorek commented Aug 5, 2025

I have added the context menu item to set a connection as default for the Workspace, to make the UX better

@Benjin
Copy link
Contributor

Benjin commented Aug 5, 2025

An interesting thought; we'll discuss taking this. Not knowing if we will end up pulling this in, I'll still leave some PR comments to make it more merge-ready if we do.

Copy link
Member

@kburtram kburtram left a comment

Choose a reason for hiding this comment

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

Overall, this looks like a solid change. Just a note that changes to the Object Explorer context menu usually require some UX consideration, as we're aiming to keep that menu focused on the most frequently used command.

@@ -443,6 +443,11 @@
"when": "view == objectExplorer && !config.mssql.useLegacyConnectionExperience && viewItem =~ /\\btype=(disconnectedServer|Server)\\b/",
"group": "1_MSSQL_serverAndDbManagement@2"
},
{
"command": "mssql.setAsWorkspaceDefault",
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this command is common enough to justify adding it to the Server node's context menu in Object Explorer. Since there are already quite a few server/database commands, adding more could clutter the menu. An alternative UX might be to expose this via the command palette, using a quick pick menu to select the server.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could also reorganize the our menu items now that VS Code supports contributing submenus. We may want to do that eventually anyway as we bring in more functionality from ADS.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we’ll likely need to reorganize our context menus as we introduce more commands. That said, we should continue to keep the menus focused on the most frequently used actions, and move less common commands to the Command Palette to reduce clutter and keep the UI clean.

package.json Outdated
@@ -1224,6 +1235,11 @@
"description": "%mssql.maxRecentConnections%",
"scope": "window"
},
"mssql.defaultConnectionName": {
"type": "string",
"description": "Name of the default connection profile to use when executing queries without an active connection. This should match the name of a saved connection profile.",
Copy link
Contributor

Choose a reason for hiding this comment

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

the default connection should be the ID (a GUID), not the profileName. Saved connections are not guaranteed to have a user-specified profile name.

mssql.defaultConnectionId would therefore be a better config value.

Copy link
Member Author

Choose a reason for hiding this comment

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

while I understand the ratio behind this request, using an ID make the settings.json less human-friendly. If I want to see what is the default connection by opening settings.json and then I just see an ID, that doesn't help much. Any idea on how to make this better while still human friendly? Are names unique or they can be duplicated?

Copy link
Member Author

Choose a reason for hiding this comment

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

May I can make a change to have the default connection highlighted in bold to improve the UI

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently bold is not possible, so I added the "(default)" description.


Utils.logDebug(`Not connected, trying default connection`);
// Try to connect with default connection from configuration
const defaultConnectionResult = await this._connectionMgr.connectWithDefaultConnection(uri);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work with other the automatic connection selection mechanisms we already have? i.e. if you have a connection selected in the Object Explorer, that connection is selected; if you already have a connected SQL file and open another one, that connection is copied to the new file.

Copy link
Member Author

@yorek yorek Aug 16, 2025

Choose a reason for hiding this comment

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

At the moment if I have a connection selected in the object explorer I'm still asked to pick a connection when I try to run a query, if the opened .sql files isn't connected to a server yet. The default connection will be used only if the .sql doesn't have an active connection already

@@ -443,6 +443,11 @@
"when": "view == objectExplorer && !config.mssql.useLegacyConnectionExperience && viewItem =~ /\\btype=(disconnectedServer|Server)\\b/",
"group": "1_MSSQL_serverAndDbManagement@2"
},
{
"command": "mssql.setAsWorkspaceDefault",
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also reorganize the our menu items now that VS Code supports contributing submenus. We may want to do that eventually anyway as we bring in more functionality from ADS.

@yorek yorek requested a review from allancascante as a code owner August 19, 2025 18:11
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.

4 participants