Grant Azure Function in staging slot MSI access to the SQL Server Database

286 Views Asked by At

I have an Azure Function (function-name) for which I granted MSI access to the SQL Server Database using the following sql query:

IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'function-name')
BEGIN
 CREATE USER [function-name] FROM EXTERNAL PROVIDER;
 ALTER ROLE db_datareader ADD MEMBER [function-name];
END

I added a staging deployment slot. How do I grant function-name in staging slot MSI access to the SQL Server Database?

1

There are 1 best solutions below

0
On

In my case, it worked like this:

CREATE USER [function-name/slots/staging] FROM EXTERNAL PROVIDER