Get-DbaDbTable does not work on Azure without access to master
Verified issue does not already exist?
Yes
What error did you receive?
The server principal 'myUser' is not able to access the database "master" under the current security context.
Steps to Reproduce
This is the example code from the question on slack:
$Server = "myserver.database.windows.net"
$cred = Get-Credential
$Database = "MyDB"
$Path = "C:\Test\test.sql"
Get-DbaDbTable -SqlInstance $Server -SqlCredential $cred -Database $Database -Table 'dbo.Tbl1', 'dbo.Tbl2', 'dbo.Tbl3' | Export-DbaDbTableData -Path $Path
Are you running the latest release?
Yes
Other details or mentions
Get-DbaDbTable uses $InputObject += Get-DbaDatabase -SqlInstance $instance -SqlCredential $SqlCredential -Database $Database -ExcludeDatabase $ExcludeDatabase, but Get-DbaDatabase only uses $server = Connect-DbaInstance -SqlInstance $instance -SqlCredential $SqlCredential, so without the database context. That will open a connection to master - and fails.
Workaround is to use Connect-DbaInstance with -Database and use the result in Get-DbaDbTable.
We can not (easily) change Get-DbaDatabase, but can we change Get-DbaDbTable to not use Get-DbaDatabase? Should we look at other commands that use Get-DbaDatabase and may have the same problem with Azure?
What PowerShell host was used when producing this error
Windows PowerShell (powershell.exe)
PowerShell Host Version
Not relevant here.
SQL Server Edition and Build number
Azure.
I think this happened before and in order to avoid changing everything, we should make sure (and state somewhere in written form) that targeting Azure sql db needs always a pre-built Connect-DbaInstance .... -Database to be passed around.
If that doesn't work, then we can go ahead and see if the particular command/function can be accomodated.
Good idea.
A blog post on the dbatools site is the best way to get that announcement out.
Will change this from a bug to a documentation issue...