How to fix issue - The server principal is not able to access the database under the current security context.

CyrusDaguro-1527 5 Reputation points
2025-01-07T03:09:06.5133333+00:00

I have a Data Factory (DF) and SQL Managed Instance (MI) with 2 databases "dbx" and "dby".

Using script activity, my DF executes my stored procedure (SP) written in X.

When SP performs a merge from dbx.Table1 to dby.Table1 --> Failure (Authorization issue as stated in question)

When SP performs a merge from dbx.Table1 to dbx.Table2 --> Success

When SP performs a merge from dby.Table1 to dby.Table2 --> Success

My authorization setup:

Using a system-managed identity, DF is assigned as SQL Managed Instance Contributor to MIUser's image

Inside both dbx and dby, I executed these commands:

CREATE USER [DF] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [DF];
ALTER ROLE db_datawriter ADD MEMBER [DF];
GRANT SELECT TO [DF];
GRANT INSERT, UPDATE, DELETE TO [DF];
GRANT EXECUTE TO [DF];
GRANT CREATE TABLE TO [DF];
GRANT ALTER TO [DF];

Hope you can help me. Thank you in advance.

Azure SQL Database
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,102 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Morillo 34,436 Reputation points MVP
    2025-01-07T03:39:21.4766667+00:00

    Would you be willing to try if enabling cross database ownership on MI solves the issue?

    EXEC sp_configure 'cross db ownership chaining', 1;
    RECONFIGURE;
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.