I am having a problem with running Sync-DlmDatabaseSchema by a specified Windows domain user against the target remote SQL server instance.
My Jenkins project runs a PowerShell task with Invoke-Command that creates a new session with specified user credentials, and executes a script that invokes Sync-DlmDatabaseSchema with New-DlmDatabaseConnection object .
The user credentials seem to be correctly taken, however
the database connection to the remote SQL server is done as anonymous user causing a login error.
If the target SQL server instance is local on the same machine as Jenkins, then the connection
to the database is done using the specified user, as expected.
#The following is the PowerShell script:
#
$SrvPassword = ConvertTo-SecureString "myPassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("Domainproc_BuildDeploy", $SrvPassword)
$s = New-PSSession -Credential $cred -ComputerName localhost
#run a scripts under the user specified
Invoke-Command -Session $s -filePath "c:mw_database_deploy_test.ps1"
# The following is the content of "c:mw_database_deploy_test.ps1" file
$build_number="1.0"
$workspace="C:workspace"
$serverInstance="mysqlremoteserver,2666"
$cur_user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$dbName="vse_master"
$source ="$workspace$dbName.$build_number.nupkg"
$target = New-DlmDatabaseConnection -ServerInstance "$serverInstance" -Database "$dbName"
Sync-DlmDatabaseSchema -Source $source -Target $target -ErrorAction Stop
# The error:
New-DlmDatabaseConnection, DLM Automation 2.0.6.240, Copyright © Red Gate Software Ltd 2014-2017
Target: database 'vse_master' on server 'mysqlremoteserver,2666'
Sync-DlmDatabaseSchema, DLM Automation 2.0.6.240, Copyright © Red Gate Software Ltd 2014-2017
Error from mw_database_deploy.ps1 script. Server Instance: mysqlremoteserver,2666, Database: vse_master.
Error Message: Couldn't connect to the database specified by the Target parameter: Login failed for user 'NT AUTHORITYANONYMOUS LOGON'..
My Jenkins project runs a PowerShell task with Invoke-Command that creates a new session with specified user credentials, and executes a script that invokes Sync-DlmDatabaseSchema with New-DlmDatabaseConnection object .
The user credentials seem to be correctly taken, however
the database connection to the remote SQL server is done as anonymous user causing a login error.
If the target SQL server instance is local on the same machine as Jenkins, then the connection
to the database is done using the specified user, as expected.
#The following is the PowerShell script:
#
$SrvPassword = ConvertTo-SecureString "myPassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("Domainproc_BuildDeploy", $SrvPassword)
$s = New-PSSession -Credential $cred -ComputerName localhost
#run a scripts under the user specified
Invoke-Command -Session $s -filePath "c:mw_database_deploy_test.ps1"
# The following is the content of "c:mw_database_deploy_test.ps1" file
$build_number="1.0"
$workspace="C:workspace"
$serverInstance="mysqlremoteserver,2666"
$cur_user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$dbName="vse_master"
$source ="$workspace$dbName.$build_number.nupkg"
$target = New-DlmDatabaseConnection -ServerInstance "$serverInstance" -Database "$dbName"
Sync-DlmDatabaseSchema -Source $source -Target $target -ErrorAction Stop
# The error:
New-DlmDatabaseConnection, DLM Automation 2.0.6.240, Copyright © Red Gate Software Ltd 2014-2017
Target: database 'vse_master' on server 'mysqlremoteserver,2666'
Sync-DlmDatabaseSchema, DLM Automation 2.0.6.240, Copyright © Red Gate Software Ltd 2014-2017
Error from mw_database_deploy.ps1 script. Server Instance: mysqlremoteserver,2666, Database: vse_master.
Error Message: Couldn't connect to the database specified by the Target parameter: Login failed for user 'NT AUTHORITYANONYMOUS LOGON'..