Skip to main content

How to fix "contained database authentication" when importing an Azure SQL Database .bacpac into local SQL Server Express

If your bacpac import into a local SQL Server Express instance fails with Msg 12824, the fix is one sp_configure setting and a clean re-import. It takes about two minutes.

I hit this while setting up the new Umbraco v17 site on my laptop. I took a .bacpac export of the latest live database and tried to restore it into SQL Server 2025 Express (MSSQL17.SQLEXPRESS), using Import Data-tier Application in SQL Server Management Studio with Windows Authentication. The import ran for a while, then stopped with "Could not import package".

The error

The important lines are the two SQL72014 errors. The SQL72012 warnings about _Data and _Log files are harmless leftovers from the failed attempt.

Error SQL72014: Framework Microsoft SqlClient Data Provider: Msg 12824, Level 16, State 1, Line 5

The sp_configure value 'contained database authentication' must be set to 1 in order to alter a contained database.


Error SQL72045: Script execution error. The executed script:

    ALTER DATABASE [$(DatabaseName)]

        SET CONTAINMENT = PARTIAL

        WITH ROLLBACK IMMEDIATE;


Error SQL72014: Framework Microsoft SqlClient Data Provider: Msg 5069, Level 16, State 1, Line 5

ALTER DATABASE statement failed.

Why it happens

The live database is a partially contained database: its users are stored inside the database rather than as server logins. That is common for databases hosted on Azure SQL.

A fresh SQL Server install has contained database authentication switched off. When the import tries to set CONTAINMENT = PARTIAL on the new database, the server refuses, and the import stops halfway, leaving an empty or partial database behind.

The fix

  1. Turn on contained database authentication. In SSMS, open a new query window on your local instance against master and run:
EXEC sp_configure 'contained database authentication', 1;
RECONFIGURE;
  1. Delete the half-created database. A bacpac can only be imported into a new, empty database. Replace the name with yours:
ALTER DATABASE [PROJECT_DATABASENAME] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE [PROJECT_DATABASENAME];

You can also right-click the database in Object Explorer, choose Delete, and tick Close existing connections.

  1. Run the import again. Same wizard, same bacpac, default data folder. This time it completes.

Connecting Umbraco

Locally you connect with your Windows account, not the contained users from live. Point the site at the restored database in appsettings.Development.json:

"ConnectionStrings": {
  "umbracoDbDSN": "Server=.\\SQLEXPRESS;Database=PROJECT_DATABASENAME;Integrated Security=true;TrustServerCertificate=true",
"umbracoDbDSN_ProviderName": "Microsoft.Data.SqlClient" }



Comments

Popular posts from this blog

How to fix "Microsoft SQL Error SQL71564: Error validating element [USERNAME]: The element [USERNAME] has been orphaned from its login and cannot be deployed."

I needed to export a database in BACPAC format today in order to restore it somewhere else, and I encountered the following error. To resolve this issue, I deleted all of the users mentioned in the error log. After successfully creating the BACPAC file, I used it to create a new database with no problems. Error: TITLE: Microsoft SQL Server Management Studio ------------------------------ One or more unsupported elements were found in the schema used as part of a data package. Error SQL71564: Error validating element [USER1]: The element [USER1] has been orphaned from its login and cannot be deployed. Error SQL71564: Error validating element [USER2]: The element [USER2] has been orphaned from its login and cannot be deployed. Error SQL71564: Error validating element [USER3]: The element [USER3] has been orphaned from its login and cannot be deployed. Error SQL71564: Error validating element [USER4]: The element [USER4] has been orphaned from its login and cannot be deployed. Error SQL71...

How to fix Git push error: "RPC failed; curl 56 HTTP/2 stream 7 was reset send-pack: unexpected disconnect while reading sideband packet fatal: the remote end hung up unexpectedly"

Problem Today I saw the following problem when I tried to push my changes to a Git server after doing some work for upgrading an Umbraco v7 project to v8.18.8.  Possible reasons After some investigations, it seems like this could be because of the following reasons; Git is not happy with the amount of changes that are being pushed into the server.  There are possible limitations on the server about the size/amount of files that you can push. Your internet connection is not good and stable enough. Your Git client's version is old. Solution options For me, the easiest option was connecting to another Wifi and trying again. Apparently, this option helped quite a few people, so it is worth giving it a try. Unfortunately, it didn't work for me. A bad internet connection wasn't an option for me either, as my internet is pretty fast (500 Mbps). Similarly, my Git client version was the latest version (git version 2.41.0.windows.3).  On StackOverflow, there were a lot of recommend...

Umbraco lifehack: How to setup anchor/jump links in Umbraco without making code changes

Today one of my clients created a ticket asking whether it is possible to set up anchor/jump links for an Umbraco content page so that they could link different sections of the page together. This is a common scenario for most Content editors and it should be super easy with any CMS platform, right? Houston, we got a problem! Now an anchor or page jump link is a special URL that takes you to a specific place on a page and it normally requires a unique HTML element ID to link different parts of a page.  When I investigated my issue, I realised that the page sections of the Umbraco page didn't have unique IDs.  View Source Code comes to the rescue In order to resolve the issue without any code changes, I decided to update the content using the built-in View Source Code feature of Umbraco CMS. This feature is available on built-in property editors, like Rich Text Editor and is super handy for checking the code that Umbraco generates for your Front-end website and making minor...