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

Restore-DbaDatabase. Set initial catalog to master #6346

Merged

Conversation

@bajmccormack
Copy link
Contributor

bajmccormack commented Jan 31, 2020

$RestoreInstance is now set using Connect-DbaInstance instead of
Connect-Sqlinstance. This change means that instead of connecting
to the inital catalogue based on your SQL login, you will always
connect to master before restoring the database. This is needed
in case your default connection puts you in the context of the
database you are trying to restore.

Type of Change

  • [ Yes ] Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (effects 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/sqlcollaborative/appveyor-lab ?
  • Nunit test is included
  • Documentation
  • Build system

Purpose

So that if restoring a database which is the same as the one you are automatically connected to, the restore will no longer fail. It's not a common scenario but it happened to me today where my initial catalog was the same as the DB I wanted to restore.

Approach

It sets the database context to master for all connections.

Commands to test

Get-ChildItem '\BACKUPS\DBName1' | Restore-DbaDatabase -SqlInstance 'DEVSQL1' -DatabaseName 'DBName1' -UseDestinationDefaultDirectories -WithReplace

Screenshots

Learning

$RestoreInstance is now set using Connect-DbaInstance instead of
Connect-Sqlinstance. This change means that instead of connecting
to the inital catalogue based on your SQL login, you will always
connect to master before restoring the database. This is needed
in case your default connection puts you in the context of the
database you are trying to restore.
@potatoqualitee

This comment has been minimized.

Copy link
Member

potatoqualitee commented Feb 1, 2020

Thanks so much BJ! Appreciate the PR. Great points - I will merge after making a slight change.

@potatoqualitee potatoqualitee merged commit cfb071f into sqlcollaborative:development Feb 1, 2020
4 checks passed
4 checks passed
Module imports on all platforms (ubuntu-latest)
Details
Module imports on all platforms (windows-latest)
Details
Module imports on all platforms (macOS-latest)
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.