Connect-DbaInstance - Set NonPooledConnection on ServerConnection for…#10260
Connect-DbaInstance - Set NonPooledConnection on ServerConnection for…#10260potatoqualitee merged 1 commit intodataplat:developmentfrom
Conversation
… DAC and NonPooled connections SqlConnectionInfo.Pooled = $false only sets Pooling=false in the connection string, but does not set ServerConnection.NonPooledConnection = $true. Without this, SMO auto-disconnects after each operation, causing rapid DAC open/close cycles that trigger SQL Server error 17810 when the next auto-connect races the prior disconnect. (do Connect-DbaInstance) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Yeah sorry I should have been clearer its a tricky one - the DBAtools commands run fine with no errors in powershell without the fix, but theres a race condition caused by cycling the connection that causes the SQL Server instance to log error 17810 "maximum number of dedicated administrator connections already exists" to the SQL Server log file if the the DAC connection isnt cleaned up quickly enough by SQL Server before the next DBATools command is sent, often the DBAtools command still succeeds anyway due to the automatic retry in SqlClient that SMO, and therefore the Connect-DbaInstance tool inherits. But if anyone is checking the sql server error logs, or has a monitoring tool that flags server errors they'll see the errors caused by this module. I've improved the commands to test section |
|
Ok, so I need to create a loop and open/close the connection multiple times to see the problem? But I still see no change, as |
|
Ok, with a loop, I can reproduce the issue: And with your fix, the issue really seems to be resolved. |
andreasjordan
left a comment
There was a problem hiding this comment.
Tested it - it works! Thanks for your contribution.
|
Brilliant thanks, I'll be sure to be clearer in the PR next time, save the confusion. |
|
Thank you so much! 🔥 🚒 |

Type of Change
Invoke-ManualPester)Purpose
Fix SQL Server error 17810 ("maximum number of dedicated administrator connections already exists") when using
Connect-DbaInstance -DedicatedAdminConnection. The DAC connection is not kept open between SMO operations becauseServerConnection.NonPooledConnectionis never set in the String input path, causing rapid connect/disconnect cycling that races against SQL Server's DAC slot release.Approach
Added
$server.ConnectionContext.NonPooledConnection = $truein the String input path ofConnect-DbaInstance, alongside the existingConnectionContextproperty assignments (BatchSeparator, LockTimeout, etc.). This is gated on$NonPooledConnectionwhich covers both-DedicatedAdminConnectionand explicit-NonPooledConnectionusage.The same pattern already exists in the Server/copy-context path (line ~711) and in
New-DbaConnectionString(line ~465) — this change brings the String input path in line with both.Commands to test
Before fix:
xp_readerrorlogreturns rows showing error 17810 logged during the DAC session (sometimes, depending on how quickly your particular SQL Server cleaned up the closing DAC connection - its an intermittant race condition).After fix: No 17810 entries — the DAC connection stays open for the duration instead of cycling.
Learning
SqlConnectionInfo.PooledandServerConnection.NonPooledConnectionare independent settings.Pooled = $falsecontrols SqlClient connection pooling (Pooling=falsein the connection string), whileNonPooledConnection = $truecontrols whether SMO auto-disconnects after each operation. Both are required for DAC connections to work correctly.