-
Notifications
You must be signed in to change notification settings - Fork 522
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
base: main
Are you sure you want to change the base?
Conversation
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 |
I have added the context menu item to set a connection as default for the Workspace, to make the UX better |
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. |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
Description
Added support for a workspace default connection as requested in #18912. The default connection is saved in the
defaultConnectionName
setting: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
npm run test
)Reviewers: Please read our reviewer guidelines