Skip to content
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

Get-DbaConnectedInstance / Disconnect-DbaInstance #7650

Merged
merged 16 commits into from Jul 30, 2021

Conversation

potatoqualitee
Copy link
Member

Proof of concept so far -- totally works

image

@andreasjordan
Copy link
Contributor

What about connections to the same instance with different Credentials or with different parameters?

@potatoqualitee
Copy link
Member Author

we can make the "key" using psboundparameters 🤔

@potatoqualitee
Copy link
Member Author

but then it may become unrecognizable

@andreasjordan
Copy link
Contributor

Maybe an array of connection objects as the value.

@potatoqualitee
Copy link
Member Author

ahh! without an index!

@potatoqualitee
Copy link
Member Author

boo, can't detect dupes

@potatoqualitee
Copy link
Member Author

ahh connectionstring as an index!

@potatoqualitee
Copy link
Member Author

love itttttt

image

@potatoqualitee potatoqualitee marked this pull request as ready for review July 30, 2021 08:11
@andreasjordan
Copy link
Contributor

image

@potatoqualitee
Copy link
Member Author

Interesting! I didn't realize that admin wasn't parsable, I'll handle it

@andreasjordan
Copy link
Contributor

We would need a change in the dll for that. Was planned here: #6831 (comment)

@andreasjordan
Copy link
Contributor

Problem 1: Disconnect should also remove the entry from the hash.
Problem 2: If you open more that one non-pooled connection, you only have one entry in the hash for more that one connection, so only one gets closed.
Problem 3: This only works for non-pooled connection. Pooled connections can only be closed with Clear-DbaConnectionPool.

@potatoqualitee
Copy link
Member Author

  1. Yep, realized that after and added a note for myself when Get showed too much
  2. No idea how to handle this
  3. Yep, it's in the description docs for Disconnect

@andreasjordan
Copy link
Contributor

About 2.: What about an array as the value to the key connectionstring:

Instead of $script:connectionhash[$server.ConnectionContext.ConnectionString] = $server something like:

if (-not $script:connectionhash[$server.ConnectionContext.ConnectionString]) {
    $script:connectionhash[$server.ConnectionContext.ConnectionString] = @( )
}
$script:connectionhash[$server.ConnectionContext.ConnectionString] += $server

You could also take the server name as key then:

if (-not $script:connectionhash[$server.Name]) {
    $script:connectionhash[$server.Name] = @( )
}
$script:connectionhash[$server.Name] += $server

@potatoqualitee
Copy link
Member Author

Mmm check it out?

Import-Module ./dbatools.psm1 -Force; Get-DbaDatabase -SqlInstance workstation | Out-null; $a = Connect-DbaInstance -SqlInstance localhost -SqlConnectionOnly; Get-DbaDatabase -SqlInstance workstation | Out-null; Get-DbaConnectedInstance

@andreasjordan
Copy link
Contributor

As the internal key is still the connection string, it might look like this:
image

So I have one connection with connections string A and two connections with connection string B.
It's ok, but might confuse the user.

@potatoqualitee
Copy link
Member Author

sweet, check it now!

image

@andreasjordan
Copy link
Contributor

Yes, looks good!

@potatoqualitee
Copy link
Member Author

Booom! Will merge once tests pass.

@potatoqualitee potatoqualitee merged commit 4ef169d into development Jul 30, 2021
@potatoqualitee potatoqualitee deleted the connection branch July 30, 2021 12:13
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.

None yet

2 participants