Intermittent ResourceNotFound (404) Error During Azure SQL Database Rename Operation

Nagothu, Venkatesh 0 Reputation points
2026-11-24T05:39:45.62+00:00

Hello Microsoft Azure SQL Team,

We are experiencing intermittent ResourceNotFound (HTTP 404) errors during Azure SQL Database rename operations in an automated daily database refresh process.

Environment:

  • Azure SQL Database

Service Tier: General Purpose – Serverless

Hardware: Gen5

Compute: 1 vCore

Source and target SQL servers: Same Azure region

Execution: Daily PowerShell automation using Azure CLI

Current process:

Copy the source database to a temporary database using az sql db copy.

Update the temporary database configuration.

Disable auto-pause on the existing target and temporary databases.

Wait approximately 30 seconds.

Rename the existing reporting database to a backup name.

Rename the temporary database to the reporting database name.

Validate the new reporting database and delete the old database.

Issue:

The database copy and configuration update generally succeed. However, the rename operation intermittently fails with the following error:

ERROR: (ResourceNotFound)
The Resource 'Microsoft.Sql/servers/<server>/databases/<database>'
under resource group '<resource-group>' was not found.

Code: ResourceNotFound
HTTP Status: 404

The issue occurs intermittently in Production, while the same PowerShell refresh logic works in Nonprod.

Azure Activity Log confirms that the first rename request in an affected execution returned ResourceNotFound. The previous day's refresh had completed successfully.

Questions:

What conditions could cause Azure SQL to return ResourceNotFound when renaming an existing database?

Could serverless auto-pause/resume or pending database configuration updates affect rename operations?

Are there known limitations or timing considerations for Azure SQL database rename operations?

What is the recommended approach for validating database readiness before renaming?

Should we implement state-aware retries instead of retrying the same rename command?

Is there a more reliable approach to maintaining a complete reporting database copy, including schema, stored procedures, and data?

We would appreciate guidance on identifying the root cause and improving the reliability of this process.

Thank you.Hello Microsoft Azure SQL Team,

We are experiencing intermittent ResourceNotFound (HTTP 404) errors during Azure SQL Database rename operations in an automated daily database refresh process.

Environment:

Azure SQL Database

Service Tier: General Purpose – Serverless

Hardware: Gen5

Compute: 1 vCore

Source and target SQL servers: Same Azure region

Execution: Daily PowerShell automation using Azure CLI

Current process:

Copy the source database to a temporary database using az sql db copy.

Update the temporary database configuration.

Disable auto-pause on the existing target and temporary databases.

Wait approximately 30 seconds.

Rename the existing reporting database to a backup name.

Rename the temporary database to the reporting database name.

Validate the new reporting database and delete the old database.

Issue:

The database copy and configuration update generally succeed. However, the rename operation intermittently fails with the following error:

ERROR: (ResourceNotFound)
The Resource 'Microsoft.Sql/servers/<server>/databases/<database>'
under resource group '<resource-group>' was not found.

Code: ResourceNotFound
HTTP Status: 404

The issue occurs intermittently in Production, while the same PowerShell refresh logic works in Nonprod.

Azure Activity Log confirms that the first rename request in an affected execution returned ResourceNotFound. The previous day's refresh had completed successfully.

Questions:

What conditions could cause Azure SQL to return ResourceNotFound when renaming an existing database?

Could serverless auto-pause/resume or pending database configuration updates affect rename operations?

Are there known limitations or timing considerations for Azure SQL database rename operations?

What is the recommended approach for validating database readiness before renaming?

Should we implement state-aware retries instead of retrying the same rename command?

Is there a more reliable approach to maintaining a complete reporting database copy, including schema, stored procedures, and data?

We would appreciate guidance on identifying the root cause and improving the reliability of this process.

Thank you.

Azure SQL Database
0 comments No comments

2 answers

Sort by: Newest
  1. Deepesh Dhake 1,325 Reputation points
    2026-11-24T14:35:27.0933333+00:00
    1. What a 404 on rename means

    A 404 means ARM couldn't resolve that exact path: subscription, resource group, server and database name. To find which part was wrong, open the failed move/action entry in the Activity Log and check the subscription and resource path in the request. Give the correlation ID to Microsoft support.

    1. Checking readiness before renaming

    Wait until no operations are pending or running on the database:

    az sql db op list --subscription $sub -g $rg -s $srv -d $db `
      --query "length([?state=='Pending' || state=='InProgress'])" -o tsv   # expect 0
    
    1. Known rename limitations

    You can't rename a database that's in geo-replication (error 40680).

    If the database uses database-level customer-managed TDE keys, reassign its managed identity right after the rename, or the database becomes inaccessible.

    A rename done with T-SQL can leave the database temporarily missing from ARM and the portal. Rename through ARM (az sql db rename) only.

    1. Geo-replica as an alternative

    A geo-secondary can be in the same region, but it has to be on a different server and it's read-only. It keeps the source database's name and can't be renamed. It only fits if reporting is read-only and your apps can use the source's name.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-11-24T05:41:06.2733333+00:00

    Replace the fixed 30-second delay with readiness gates for copy completion, configuration completion, online status, and connection quiescence, then reconcile both database names before retrying any rename.

    1. Wait for the copied database to become ONLINE.
      az sql db copy is asynchronous: the target resource appears immediately, while the actual copy can remain in COPYING. A successful copy changes sys.databases.state_desc to ONLINE; SUSPECT indicates failure.^1^
    2. Wait for configuration operations to finish.
      Changing compute or serverless settings can start an asynchronous database operation. Poll until az sql db op list returns no operations in InProgress state.^2^
    3. Confirm the control-plane status is Online.
      Query each database with az sql db show --query status; do not proceed merely because the preceding CLI command returned successfully.^3^
    4. Stop reporting traffic and drain connections.
      Azure SQL Database cannot be renamed while other users have open connections. Unlike SQL Server, the documented Azure SQL procedure requires the clients to be disconnected rather than forcing SINGLE_USER mode.^4^
    5. Rename sequentially and verify each postcondition.
      az sql db rename is a supported command, but rename is not idempotent because it changes the resource identifier.^5^ The management operation targets the old database resource and moves it to an ID containing the new name.^6^

    A compact PowerShell gate can replace the fixed sleep:

    function Wait-DbReady($rg, $server, $db) {
        for ($i = 0; $i -lt 60; $i++) {
            $status = az sql db show -g $rg -s $server -n $db `
                --query status -o tsv 2>$null
            $ops = az sql db op list -g $rg -s $server --database $db `
                --query "[?state=='InProgress'].name" -o tsv 2>$null
    
            if ($LASTEXITCODE -eq 0 -and $status -eq "Online" -and !$ops) {
                return
            }
            Start-Sleep -Seconds ([Math]::Min(60, 5 * [Math]::Pow(2, $i / 5)))
        }
        throw "Database '$db' did not become ready before timeout."
    }
    

    Also query sys.databases and sys.dm_operation_status from master when possible. The latter records copy, alter, service-tier, restore, and delete operations, including state_desc, completion percentage, and error details.^7^

    Retry by observed state—not by repeating the command

    After a failed or timed-out rename, query both the old and new names:

    • Old exists, new does not: retry the rename with bounded exponential backoff and jitter.
    • Old does not exist, new exists: the rename probably completed; continue with validation.
    • Both exist: stop; do not overwrite or delete either database automatically.
    • Neither exists: stop and escalate; verify subscription, resource group, server, and names.
    • Either resource has an in-progress operation: wait, then reconcile again.

    Azure Resource Manager can experience intermittent management-operation failures, but Microsoft recommends checking operation state before retrying and determining whether repeating the request is safe.^8^ A ResourceNotFound response specifically means Resource Manager could not retrieve the addressed resource; the documented first checks are resource name, resource group, and subscription.^9^

    Serverless and other rename constraints

    Auto-resume is not a documented explanation for this exact management-plane 404. A paused serverless database normally resumes on a login attempt; that first connection can return SQL error 40613, and resume generally takes less than one minute.^10^ Disabling auto-pause immediately before rename is therefore not a substitute for polling readiness, particularly when configuration changes are still pending.

    Also verify these supported rename prerequisites:

    • No active connections.
    • The automation identity has ALTER permission when using T-SQL.
    • The database is not in active geo-replication.^4^
    • If it belongs to a failover group, remove it from that relationship before rename; database rename is unsupported within a failover group.^11^

    There is no authoritative published known issue in the supplied product documentation specifically identifying intermittent 404 ResourceNotFound from az sql db rename. Preserve the failed Activity Log event, timestamp, correlation ID, command parameters, CLI version, and the old/new-name state immediately afterward. If readiness gating does not eliminate the failures, provide those records to Azure Support for backend tracing.

    Complete reporting copy

    Continue using Azure SQL database copy when the requirement is a complete, transactionally consistent point-in-time copy. After completion, it is an independent, fully functional database; database users, permissions, and SIDs are copied, and the same-server scenario can use the same logins.^1^ This is more suitable than a Data Factory Copy activity when stored procedures and other database objects must be preserved.

    The reliability issue is therefore best addressed by keeping database copy but replacing fixed sleeps and blind rename retries with explicit operation-state polling, connection draining, and old/new-name reconciliation.


    References

    1. Copy a transactionally consistent copy of a database in Azure SQL Database
    2. Lists the names of ongoing operations on a specified Azure SQL Database using Azure CLI in a Cloud Shell environment.
    3. Retrieves the current status of an Azure SQL Database using Azure CLI by specifying the database name, resource group, and server, then querying the 'status' pr...
    4. Rename a Database - SQL Server | Microsoft Learn
    5. az sql db rename
    6. Databases - Rename - REST API (Azure SQL Database) | Microsoft Learn
    7. sys.dm_operation_status
    8. Reliability in Azure Resource Manager
    9. Resolve errors for resource not found
    10. Auto-pause and auto-resume in the serverless compute tier for Azure SQL Database
    11. Configure a failover group for Azure SQL Database (azure-sql-single-db)
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

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