Install-DbaMaintenanceSolution - Leave the connection of the caller alone - #10570
Merged
potatoqualitee merged 1 commit intoAug 13, 2026
Merged
Conversation
…lone The command closed its connection when it was done, no matter whether it had opened it or whether the caller handed one over. Connect-DbaInstance now reports that through -IsNewConnectionReference. The disconnect was also hiding that the cleanup of the existing objects ran through $db.Invoke(), which leaves the connection in that database. The installation of the scripts a few lines below already names the database with Invoke-DbaQuery, so the cleanup now does the same. See #10554 and #10555 (do Install-DbaMaintenanceSolution) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
|
thank you 🙏🏼 |
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.
Fourth of the sites listed in #10554.
The disconnect
The command closed its connection when it was done, without asking whether it had opened it. When a caller passes their own server object,
Connect-DbaInstancehands the same object back, and the command then closed the connection of the caller, taking the session with it. It now only closes what it opened itself.The leak the disconnect was hiding
With
-ReplaceExisting, the existing objects are dropped through$db.Invoke($cleanupQuery), which runs on the connection of the caller and leaves it in that database - #10555. The disconnect covered that up, because the connection was closed right afterwards.The installation of the scripts a few lines below already names the database:
so the cleanup now does the same. Same statements, same database, and the connection of the caller is untouched.
Tests
A new context installs with
-ReplaceExistingthrough a connection the caller opened, and asserts that the session survives and that the connection is still onmaster. Each assertion covers one of the two changes, verified by putting each one back:Jobs are deliberately left out of that context (
-InstallJobsnot set), because the SQL Agent commands move the connection themselves -New-DbaAgentJobandRemove-DbaAgentJobare their own sites of #10555 and are not touched here.Install-DbaMaintenanceSolutionpasses 52 of 52 against SQL Server 2025 and 2022, in 20 minutes.This text was created by Claude and reviewed by Andreas Jordan.