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

Connect-DbaInstance: Fix for issue when changing database context #9505

Merged
merged 3 commits into from
Oct 14, 2024

Conversation

andreasjordan
Copy link
Contributor

@andreasjordan andreasjordan commented Oct 13, 2024

Type of Change

  • Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (affects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (.\tests\manual.pester.ps1)
  • 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

The problem was discovered while working on the test for Remove-DbaDbTableData. Inside of Backup-DabaDatabase changing the database context to master was not possible and resulted in using a cached connection to an already dropped database.

In the first commit, I added a test inside of Connect-DbaInstance to write a warning:

if ($Database -and $server.ConnectionContext.CurrentDatabase -ne $Database) {
    Write-Message -Level Warning -Message "Changing connection context to database $Database was not successful. Current database is $($server.ConnectionContext.CurrentDatabase). Please open an issue on https://github.com/dataplat/dbatools/issues."
}

In the second commit I added a test to show the warning:

image

In the third commit, I implement the fix, changing $connContext = $connContext.GetDatabaseConnection($Database) to $connContext = $connContext.GetDatabaseConnection($Database, $false).

@andreasjordan andreasjordan marked this pull request as ready for review October 13, 2024 18:59
@potatoqualitee
Copy link
Member

I really like this solution, thank you!

@potatoqualitee potatoqualitee merged commit 0b9be65 into development Oct 14, 2024
13 checks passed
@potatoqualitee potatoqualitee deleted the ConnectDbaInstance_fix_connection_pooling branch October 14, 2024 08:10
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.

2 participants