-
-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect-DbaInstance - Use DAC with new switch DedicatedAdminConnection #7644
Conversation
sweet! |
If there is already a DAC connection, this erro is raised: The specified network name is no longer available. |
functions/Connect-DbaInstance.ps1
Outdated
Connects using "ADMIN:" to create a dedicated admin connection (DAC). | ||
If the instance is on a remote server, the remote access has to be enabled via "sp_configure 'remote admin connections', 1". | ||
The parameter NonPooledConnection will be set to request a non-pooled connection. | ||
The connection will not be closed if the variable holding the Server SMO is going ot of scope, so it is very important to call .ConnectionContext.Disconnect() to close the connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can we do this/detect idle in runspaces? Can we create a Disconnect-DbaInstance
command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disconnect-DbaInstance
is a good idea. But for that we would have to build a cache (like for TEPP) where Connect-DbaInstance saves (registers) all connections it opens. Then Disconnect-DbaInstance -SqlInstance XYZ
could get all connections from cache and close them. Disconnect-DbaInstance -SqlInstance XYZ -Force
could connect to the instance and get all connections based on the client name and kill them.
Perhaps we can catch that -- if DedicatedAdminConnection and errmsg -match "The specified network name is no longer available." then errmsg = "Only one DAC connection is allowed etc" |
error messages are translated .... either we force english on powershell or parsing the error message text is going to be hard |
Added a general message on failure with DAC. |
good point, niph! i like the solution @andreasjordan ! |
If we want to build a "cache" to be able to implement |
you and me, probably ;) we can also use a good ol
|
Ok, I'll play with that and see what I can do... |
I think We have a general problem with the Server SMO or the way we work with them: It does not have a destructor we can use to disconnect. This is not a problem with pooled connections, there is even
So this works:
The call to This does not work so well:
The call to But if we change We would have to check inside of I think the basic problem is that a |
since you are working with $Script: variable, you will need to do everything inside of the module. Build |
we'll probably want a |
The problem is that we don't get it to be in sync. The $Script: variable can hold a bunch on connections, but we don't know which of them are still bound to a variable in the user scope. And this would only be needed for non-pooled connections. And we only have four commands that request a non-pooled connection:
I would like to address this in a seperate pull request and just add the switch for DAC here. |
oh totally. i'll do a POC in another branch after i create tests for the compression commands |
fabulous 🤩 ! |
Type of Change
.\tests\manual.pester.ps1
)Just first ideas.
Problem: Non-pooled connections do not get closed when variable with Server SMO is removed or goes out of scope. But this is not related to DAC but a general problem we should address before thinking about merging this.
It currently only works with input type RegisteredServer, ConnectionString and String, not with Server or SqlConnection. Server could be easily handled with ConnectionContext.Copy(), just haven't coded it yet.