Skip to content

Update-SqlPermission - Remove unnecessary SqlConnectionObject.Close() calls#10291

Merged
potatoqualitee merged 1 commit intodevelopmentfrom
claude/issue-10284-20260328-1626
Mar 29, 2026
Merged

Update-SqlPermission - Remove unnecessary SqlConnectionObject.Close() calls#10291
potatoqualitee merged 1 commit intodevelopmentfrom
claude/issue-10284-20260328-1626

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Remove 11 Close() calls across 6 locations in Update-SqlPermission that caused 30-40 "max 1 DAC connections" errors in the SQL Error Log when Sync-DbaAvailabilityGroup runs.

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

… 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>
@andreasjordan andreasjordan marked this pull request as draft March 29, 2026 09:54
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

I need to test this in my lab as the command is maybe not covered by the tests.

@andreasjordan andreasjordan marked this pull request as ready for review March 29, 2026 12:05
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

Successfully tested in my lab.

@potatoqualitee potatoqualitee merged commit 899cdc3 into development Mar 29, 2026
17 of 18 checks passed
@potatoqualitee potatoqualitee deleted the claude/issue-10284-20260328-1626 branch March 29, 2026 19:18
@potatoqualitee
Copy link
Copy Markdown
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>
potatoqualitee added a commit that referenced this pull request Apr 11, 2026
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.

Sync-DbaAvailabilityGroup generates excessive amount of DAC connection errors since v2.7.25 in SQL Error Log

2 participants