Insufficient Permissions Error with Azure Service Principal on CREATE DATABASE AS COPY OF

55671899 0 Reputation points
2025-04-24T14:50:01.6966667+00:00

An attempt is being made to execute the CREATE DATABASE AS COPY OF statement that references a source database on the same Azure SQL Server and elastic pool.

  • The implementation uses an external login mapping to an Azure app registration
  • The login has dbmanager permission on the Azure SQL Server
  • User has db_owner permission on the source Azure SQL database.

However, the execution fails despite these configurations.

The following script has been used:

CREATE LOGIN [azure-app-registation] FROM EXTERNAL PROVIDER
GO

USE [master] 
GO 
EXEC sp_addrolemember N'dbmanager', N'user1'
GO

USE [source-db] 
GO 
EXEC sp_addrolemember N'db_owner', N'user1'
GO

CREATE DATABASE [source-db-new] AS COPY OF [source-db] (SERVICE_OBJECTIVE = ELASTIC_POOL(NAME = "my-elasticpool"))
GO

The error message received is:
Msg 45137, Level 16, State 1, Line 1 Insufficient permission to create a database copy on server '<servername>'. Ensure that the user login '<azure client id>@<azure tenant id>' has the correct permissions on the source and target servers.

The source db was not created by same login and so if I try to do this it let me run that but it is not expected behavior:

ALTER AUTHORIZATION ON DATABASE::[soruce-db] TO [azure-app-registation]

Azure reference: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-database-transact-sql?view=azuresqldb-current&preserve-view=true&tabs=sqlpool#permissions-1

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. PratikLad 960 Reputation points Microsoft External Staff
    2025-04-30T12:38:39.5433333+00:00

    Hi @55671899,

    To Copy azure SQL database to an elastic pool the identity (<azure client id>@<azure tenant id>) must meet these conditions:

    On the Source Server (where the database is being copied from):

    • The identity user must have the dbmanager role at the in the master database.
    • The identity user Must have the db_owner role at the in the source database.

    Steps to Copy azure sql database to an elastic pool:

    --Step# 1  
    --Create login and user in the master database of the source server.  
    CREATE LOGIN [azure-app-registation] FROM  EXTERNAL PROVIDER
    GO  
    CREATE USER [azure-app-registation] FOR LOGIN [azure-app-registation];  
    GO  
    ALTER ROLE dbmanager ADD MEMBER [azure-app-registation]a;  
    GO  
      
    --Step# 2  
    --Create the user in the source database and grant dbowner permission to the database.  
    CREATE USER [azure-app-registation] FOR LOGIN [azure-app-registation];   
    GO  
    ALTER ROLE db_owner ADD MEMBER [azure-app-registation];  
    GO  
    --Step# 3
    --Sign in to the `master` database with the login that created the database you want to copy.
    CREATE  DATABASE Database2 AS COPY OF Database1 (SERVICE_OBJECTIVE = ELASTIC_POOL( name = pool1 ));  
    

    Here is my Output:

    enter image description here


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.