sql-serverazure-pipelinescicdazure-pipelines-release-pipelinedatabase-deployment

Azure SQL Database Deployment "ALTER DATABASE failed because a lock could not be placed on database"


I've gotten myself a little stuck.

We've been using Azure DevOps release pipelines to deploy DacPacs to all our internal test database environments. Some of these are Azure SQL databases, and others are SQL Server databases on real machines/VMs that are set up as deployment agents.

All the databases are the same, so we eventually deploy to them all using the same DacPac. The one with the issue is using the SQL Server database deploy task.

The process works great apart from one issue that keeps popping up. One of the VMs hosting a SQL Server database instance keeps failing it's deployment with ALTER DATABASE failed because a lock could not be placed on database.

I can hop on the server, kill any processes on the SQL Server and try running the release again, and it will eventually work. The odd thing is I the processes I see are usually only my own from logging on to the server and opening SSMS. Sometimes there are existing processes, but these don't causes issues with other servers.

I'm not great at SQL server management, so honestly any steps/advice that would work with our automated processes would be greatly appreciated.


Solution

  • Thanks to everyone for the comments, helped me understand the issue and solve the problem.

    The solution was to add /p:ScriptDatabaseOptions=false to my SqlPackage.exe deployment command. (I added to additional parameters on my release pipeline).

    I didn't want database settings to be changed with my DacPac deployment anyway, so it was a fine solution for me.