microsoft / microsoft/DacFx

SqlPackage.exe /a:Publish creates Alter Database statement that is invalid on Azure Managed Instance

Open
#68 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: deployment bug sqlmi
Dominant language
C#
Stars
460
Forks
29
Avg merge
4d 9h
Merged PRs (30d)
7

Description

**Steps to Reproduce:**

**Local Environment:**
Using .NET Core version of sqlpackage.exe 15.0.5282.3 in an Administrator Command Prompt on my Windows 10 laptop.

**Target Environment:**
Azure SQL Managed Instance (Business Critical)

I run the following command in an Administrtor Command Prompt on my local PC.
SqlPackage /a:Extract /ssn:tcp:managed.instance.database.windows.net,1433 /sdn:SourceDatabaseName /tf:"C:\temp\database.dacpac" /su:AdminAccount /sp:TheAdminPassword /p:VerifyExtraction=False /p:ExtractAllTableData=True

I then try to Publish that successfully created dacpac from my local PC to my Azure SQL Managed Instance. I am using this command in the command prompt window:
SqlPackage /a:Publish /sf:"C:\temp\database.dacpac" /tsn:tcp:managed.instance.database.windows.net,1433 /tdn:NewDatabaseName /tu:AdminAccount /tp:TheAdminPassword /p:ExcludeObjectTypes=Logins;RoleMembership /d:True /p:ScriptDatabaseOptions=True /p:DatabaseEdition="BusinessCritical"

The SqlPackage Publish script goes through and creates the schema
Initializing deployment (Start)
Initializing deployment (Complete)
Analyzing deployment plan (Start)
Analyzing deployment plan (Complete)
Updating database (Start)
Update complete.
An error occurred while the batch was being executed.
An error occurred while the batch was being executed.
Updating database (Failed)
*** Could not deploy package.
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 5008, Level 16, State 11, Line 1 This ALTER DATABASE statement is not supported. Correct the syntax and execute the statement again.
Error SQL72045: Script execution error. The executed script:
ALTER DATABASE [$(DatabaseName)]
SET READ_WRITE
WITH ROLLBACK IMMEDIATE
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 5069, Level 16, State 1, Line 1 ALTER DATABASE statement failed.
Error SQL72045: Script execution error. The executed script:
**ALTER DATABASE [$(DatabaseName)]
SET READ_WRITE
WITH ROLLBACK IMMEDIATE**

It seems to get to the part where it will then start updating the table rows. It scripts out an Alter Database command that isn't allowed on an Azure SQL Managed Instance. It then immediately fails.

This is my first time using sqlpackage.exe.

If I issue the command **ALTER DATABASE [TheDatabaseName] SET READ_WRITE WITH ROLLBACK IMMEDIATE** directly in SSMS while connected to the Managed Instance, I get the same 2 errors.

Update 2022-02-23:
Using .NET Core version of sqlpackage.exe 16.0.5400.1 in an Administrator Command Prompt on my Windows 10 laptop.

I ran "sqlpackage.exe /Action:Import" on a bacpac to my Azure SQL Server Managed Instance and I get the same error.
Creating deployment plan
Initializing deployment
Verifying deployment plan
Analyzing deployment plan
Importing package schema and data into database
Updating database
*** Error importing database:Could not import package.
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 5008, Level 16, State 11, Line 1 This ALTER DATABASE statement is not supported. Correct the syntax and execute the statement again.
Error SQL72045: Script execution error. The executed script:
ALTER DATABASE [$(DatabaseName)]
SET READ_WRITE
WITH ROLLBACK IMMEDIATE
Error SQL72014: Core Microsoft SqlClient Data Provider: Msg 5069, Level 16, State 1, Line 1 ALTER DATABASE statement failed.
Error SQL72045: Script execution error. The executed script:
ALTER DATABASE [$(DatabaseName)]
SET READ_WRITE
WITH ROLLBACK IMMEDIATE

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SqlPackage /a:Publish and /Action:Import paths and reproduce the deployment against Azure SQL Managed Instance using the commands and package details in the report. Trace where the generated deployment script emits ALTER DATABASE ... SET READ_WRITE, then verify that a deployment no longer fails with SQL72014 and SQL72045.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, sql
Domain
cloud, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.