Skip to content

Fix DAC connection reuse detection causing excessive DAC errors in Sync-DbaAvailabilityGroup#10289

Closed
andreasjordan wants to merge 1 commit into
developmentfrom
claude/issue-10284-20260327-2247
Closed

Fix DAC connection reuse detection causing excessive DAC errors in Sync-DbaAvailabilityGroup#10289
andreasjordan wants to merge 1 commit into
developmentfrom
claude/issue-10284-20260327-2247

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Fix two bugs introduced in v2.7.25 that cause 30-40 "max 1 DAC connections" errors in the SQL Error Log when Sync-DbaAvailabilityGroup runs.

Bug 1: dacConnected check used Server.Name instead of ConnectionContext.ServerInstance

Server.Name never has the ADMIN: prefix for DAC connections — that lives in ConnectionContext.ServerInstance. The broken check caused Copy-DbaCredential, Copy-DbaDbMail, and Copy-DbaLinkedServer to always think no DAC was open, set $dacOpened = $true, and disconnect the shared DAC in their end blocks.

Bug 2: Sync-DbaLoginPermission received the DAC server object

Update-SqlPermission calls SqlConnectionObject.Close() in tight loops (per role per database per login). With a DAC connection, each Close() physically terminates the TCP connection and the next SMO operation immediately tries to reconnect to ADMIN:server. TCP close propagation timing causes SQL Server to see the old connection as still active, generating the errors.

Fixes #10284

Generated with Claude Code) | [View branch](https://github.com/dataplat/dbatools/tree/claude/issue-10284-20260327-2247

…nc-DbaAvailabilityGroup

The dacConnected check in multiple commands was checking Server.Name for the ADMIN:
prefix, but the ADMIN: prefix lives in ConnectionContext.ServerInstance. Since Server.Name
never starts with ADMIN:, the check always returned false - causing commands to mark
$dacOpened = $true and disconnect the shared DAC connection at their end blocks.

This resulted in Sync-DbaAvailabilityGroup's DAC being unintentionally closed by each
sub-command (Copy-DbaCredential, Copy-DbaDbMail, Copy-DbaLinkedServer).

Additionally, Sync-DbaLoginPermission was passed the DAC server object. Update-SqlPermission
calls SqlConnectionObject.Close() in tight loops (per role per database per login), causing
repeated DAC slot acquire/release cycles that trigger "max 1 DAC connections" SQL errors.

Fixes:
- Change all dacConnected checks from .InputObject.Name to
  .InputObject.ConnectionContext.ServerInstance (or .Parent.ConnectionContext.ServerInstance)
- In Sync-DbaAvailabilityGroup, pass DomainInstanceName string to Sync-DbaLoginPermission
  so it opens a normal pooled connection instead of reusing the DAC server

Fixes #10284

(do *AvailabilityGroup*, *Credential*, *LinkedServer*, *DbMail*, *Migration*, *Decrypt*)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

I will test this this weekend.

@andreasjordan
Copy link
Copy Markdown
Collaborator Author

See issue on details why I closed this.

@andreasjordan andreasjordan deleted the claude/issue-10284-20260327-2247 branch March 28, 2026 16:22
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

1 participant