Why do we get error 'Database already exists' during recovery on new sql managed instance. (false-positive)

Kjell Bulcke 0 Reputation points
2025-10-30T11:30:52.0833333+00:00

First of all.
This is more a question to see if we can just ignore this error because everything works perfectly except for the false error. (It took a few hours to realize this).

Scenario: We recover a .bak (located in a Storage Account) into a Azure Managed Instance for a legacy app that rarely needs consulting. The Managed Instance gets removed and re-deployed from scratch when needed.

During the recovery process we run into the following error but the recovery still succeeds.
Microsoft.Data.SqlClient.SqlError: Database already exists. Choose a different database name.

When running the following query 2 rows get returned.
One with error code 1801 - Database already exists.
One with no error code that says recovery completed.

SELECT *
FROM sys.dm_operation_status
WHERE resource_type_desc = 'DATABASE'
ORDER BY start_time DESC;

Find it a bit strange the error pops up but everything works perfectly.
The program connects to the database and all data is available.

Azure SQL Database
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 127.7K Reputation points MVP Volunteer Moderator
    2025-10-30T21:52:30.51+00:00

    Given the occurrence of SqlClient in the error message, I will have to assume that you are using SSMS to do the restore. It seems that SSMS in the middle of the operation gets the idea to run some different command which produces this error.

    Personally, I prefer to run BACKUP/RESTORE operations directly from T-SQL. The eliminates the risk that SSMS is too smart for its own good.

    1 person found 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.