An exception occurred while enqueueing a message in the target queue. Error: 15517, State: 1. Cannot execute as the database principal because the principal “dbo” does not exist, this type of principal cannot be impersonated, or you do not have permission.


This only works with Windows server 2012R2. If you are using 2016 then use SQL server manager studio

Run the following powershell command on the primary ADFS server

Open an administrative powershell

Change the service account

#Service Account ADFS
$_account = “domain\adfsserviceaccount”

#Connect to the local WID, this does not require the SQL PowerShell module
$_db_connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
$_db_connection.ConnectionString =
“Server=\\.\pipe\MICROSOFT##WID\tsql\query;Database=AdfsConfiguration;Integrated Security=True;”
#Create a command and run a T-SQL query
$_db_command = $_db_connection.CreateCommand()
$_upade = @”
from sys.schemas s
where s.principal_id = user_id(‘$_account’)
alter authorization on schema::identityServerPolicy to dbo
use adfsconfiguration exec sp_dropuser ‘$_account’
use adfsconfiguration exec sp_changedbowner ‘$_account’
use adfsartifactstore exec sp_dropuser ‘$_account’
use adfsartifactstore exec sp_changedbowner ‘$_account’
$_db_command.CommandText = $_upade
#Load the results in a table
$_db_results = $_db_command.ExecuteReader()
$_data_table = New-Object -TypeName System.Data.DataTable
$_data_value = $_data_table.Value
#Close the connection with the local DB

11503 Total Views 2 Views Today

Leave a Comment

Leave a Reply