Copy-DbaDbTableData fails login when copying data from on-premise to azure sql database
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Login failed for user 'login_tst_dbo'
Steps to Reproduce
# sql credentials - not ad credentals
$sourceCredential = Get-Credential -Title "Source Credentials" -Message "Enter credentials for the source server" -UserName 'sourceUser'
$destinationCredential = Get-Credential -Title "Destination Credentials" -Message "Enter credentials for the destination server" -UserName 'destUser'
# source is using port 4133 which a firewall nats to 1433, so for testing purposes "sqldmz,1433" could be used as source
Copy-DbaDbTableData `
-SqlInstance "sqldmz,4133" `
-Destination "tcp:azuresql.database.windows.net,1433" `
-Database "sourceDB" `
-DestinationDatabase "destinationDB" `
-Table Clients `
-SqlCredential $sourceCredential `
-DestinationSqlCredential $destinationCredential `
-AutoCreateTable `
-Truncate `
-EnableException `
-Verbose
}
Please confirm that you are running the most recent version of dbatools
2.1.5
Other details or mentions
Connecting to the databases using the same credentials og running Invoke-DbaQuery works fine in the same code
Invoke-DbaQuery -SqlInstance "sqldmz,4133" -Database "sourceDB" -Query "SELECT name FROM sys.tables" -SqlCredential $destinationCredential -MessagesToOutput
Invoke-DbaQuery -SqlInstance "tcp:azuresql.database.windows.net,1433" -Database "destinationDB" -Query "SELECT name FROM sys.tables" -SqlCredential $destinationCredential -MessagesToOutput
Connecting to the target sql server without the database name results in the same error. The user used only have access to that database and no other - and I think that might be the cause of the issue
Invoke-DbaQuery -SqlInstance "tcp:azuresql.database.windows.net,1433" -query 'select @@version' -SqlCredential $destinationCredential
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
Name Value
PSVersion 7.4.0 PSEdition Core GitCommitId 7.4.0 OS Microsoft Windows 10.0.20348 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0
SQL Server Edition and Build number
Source server: Microsoft SQL Server 2019 (RTM-CU23) (KB5030333) - 15.0.4335.1 (X64) Sep 21 2023 17:28:44 Copyright (C) 2019 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2019 Standard 10.0
.NET Framework Version
.NET 8.0.0
I seem to recall this has always been a problem 🤔
Congrats, you have found a bug.
The connection to the target server is made without the database parameter ($destServer = Connect-DbaInstance -SqlInstance $destinstance -SqlCredential $DestinationSqlCredential).
Until we fix this, you can work around this by using $dest = Connect-DbaInstance to connect to the target and use $dest as the Destination parameter.