Update-SqlPermission - Remove unnecessary SqlConnectionObject.Close() calls#10291
Merged
potatoqualitee merged 1 commit intodevelopmentfrom Mar 29, 2026
Merged
Conversation
… calls The Close() calls were added as a workaround for SMO DataReader conflicts, but modern SMO properly manages its own connection lifecycle - all Enum* methods (EnumMembers, EnumServerPermissions, EnumDatabasePermissions, etc.) open and close their DataReaders internally via SqlDataAdapter.Fill(). The calls were harmless with normal pooled connections (Close() returns to the pool, next Open() gets a fresh connection) but catastrophic with DAC connections: each Close() terminates the single DAC TCP slot, and the reconnect attempt to ADMIN:server fails when the slot hasn't been freed yet, generating "max 1 dedicated administrator connections" errors. The worst case was the Close() pair inside the foreach ($role in $sourceDb.Roles) loop - called once per role per database per login, producing 30-40 DAC errors in the scenario reported in #10284. Fixes #10284 (do Sync-DbaAvailabilityGroup) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
Collaborator
Author
|
I need to test this in my lab as the command is maybe not covered by the tests. |
Collaborator
Author
|
Successfully tested in my lab. |
Member
|
Appreciate it 🤝 |
potatoqualitee
added a commit
that referenced
this pull request
Apr 10, 2026
…c (review of #10291) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Remove 11
Close()calls across 6 locations inUpdate-SqlPermissionthat caused 30-40 "max 1 DAC connections" errors in the SQL Error Log whenSync-DbaAvailabilityGroupruns.The calls were added as a workaround for SMO DataReader conflicts, but modern SMO properly manages its own connection lifecycle - all Enum* methods open and close their DataReaders internally via SqlDataAdapter.Fill().
The calls were harmless with normal pooled connections but catastrophic with DAC connections: each Close() terminates the single DAC TCP slot, and the reconnect attempt to ADMIN:server fails when the slot hasn't been freed yet.
The worst offender was the Close() pair inside the
foreach ($role in $sourceDb.Roles)loop - called once per role per database per login, producing 30-40 DAC errors in the scenario reported in #10284.Fixes #10284
Generated with Claude Code