Skip to content

Connect-DbaInstance / Invoke-DbaQuery - Open a correct new connection when ConnectAsUserName is used and fix usage of AppendConnectionString #9680

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

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

andreasjordan
Copy link
Contributor

@andreasjordan andreasjordan commented May 22, 2025

@niphlod - please have a look at the changes. If you like them you can include them in your PR or we can use this PR.

Type of Change

  • Bug fix (non-breaking change, fixes Getting warning using Connection object from Connect-DbaInstance with Invoke-DbaQuery #9665 )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (affects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (Invoke-ManualPester)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
  • Unit test is included
  • Documentation
  • Build system

Purpose

This PR addresses two topics:

  • Connections that use a windows credential as SqlCredential must not lose this information when they are processed by Connect-DbaInstance.
  • It should be able to pass additional connection information to Invoke-DbaQuery via AppendConnectionString.

Approach

While processing a Server SMO inside of Connect-DbaInstance, we identify the usage of windows credentials in case we need to change the connection context because of the given parameters. We then force a completly new connection instead of changing the current connection.
We also identify the usage of windows credentials inside of Invoke-DbaQuery while we test if we can reuse an existing connection or if we have to use Connect-DbaInstance to create a new connection or modify the existing connection.

Commands to test

Screenshots

Learning

@andreasjordan
Copy link
Contributor Author

Tests show that there are new problems with changing database context. I will try to look at that tomorrow.

@andreasjordan andreasjordan changed the title proposed changes to fix problems with ConnectAsUserName Connect-DbaInstance / Invoke-DbaQuery - Open a correct new connection when ConnectAsUserName is used and fix usage of AppendConnectionString May 23, 2025
@andreasjordan
Copy link
Contributor Author

Ok, @niphlod - now you can have a look.

I basically moved your code to Connect-DbaInstance to generally support this case and just changed Invoke-DbaQuery a bit so that AppendConnectionString is forcing a new connection.

@andreasjordan
Copy link
Contributor Author

Ups, just forgot the case when AppendConnectionString is used with a simple open connection. Will add this soon...

@niphlod
Copy link
Contributor

niphlod commented May 26, 2025

sorry @andreasjordan , I'm a bit lost in here. Can I use this PR in lieu of #9667 to see if everything works ?

@andreasjordan
Copy link
Contributor Author

Yes. We can just merge this PR here to solve the issue. It's mostly your code - just a bit rearranged.

@niphlod
Copy link
Contributor

niphlod commented May 26, 2025

ok, lemme try a few combinations then, I'll close mine and approve this as soon as it works as expected.

@niphlod
Copy link
Contributor

niphlod commented May 26, 2025

@andreasjordan , approved!

@andreasjordan
Copy link
Contributor Author

Just added Purpose and Approach to the initial post.

@potatoqualitee if you need anything else before merging, please let me know.

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.

Getting warning using Connection object from Connect-DbaInstance with Invoke-DbaQuery
2 participants