"Only active directory users can impersonate other active directory users" when accessing an Azure SQL Database
Not long ago I faced the following error.
System.Data.SqlClient.SqlException (0x80131904): Only active directory users can impersonate other active directory users.
at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__180_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
...so on...
Everything looked correct (such as the connection string containing the credential to connect the database was correct and the user seemed to have the correct permissions as well) therefore, I spent some time understanding further about SQL.
I did find some MSDN article talking about “EXECUTE AS”
however, I still didn’t really know the actual issue and I couldn’t find
many other available online articles related to this issue at that
time, so hopefully, this article could save someone else’s time.
Eventually, I found out that there is a part in Azure which shows us the detail of our SQL server, such as:
Overview of SQL Server |
The above error will occur if the database’s owner is set to be the same with the field “Active Directory admin” and the error can be avoided by using the user in “Server admin”.
You
can check the database’s owner by opening the SSMS application to
connect to your database server, do right click on the related database,
and click “Properties” to see what is the current “Owner” of the
database.
One of the ways to change it is to run a SQL query as follows:
ALTER AUTHORIZATION ON DATABASE::YourDatabaseName TO YourDbOwner
Comments
Post a Comment