SQL Azure Database Unable to restore bacpac due to foreign key conflict

0 votes

I'm attempting to restore a backup (.bacpac) of one SQL Azure database to another SQL Azure database but I am getting the following error:

Error encountered during the service operation. Could not import package. Error SQL72014: .Net SqlClient Data Provider: Msg 547, Level 16, State 0, Line 3 The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_x_xx". The conflict occurred in database "x", table "dbo.x". Error SQL72045: Script execution error. The executed script: PRINT N'Checking constraint: FK_x_xx[dbo].[x]'; ALTER TABLE [dbo].[x] WITH CHECK CHECK CONSTRAINT [FK_x_xx];

I have also attempted to restore locally without success with a mscorlib exception. And I've also checked the live database and I can't see why this key is being violated.

Apr 2, 2019 in Azure by sabby
• 4,370 points
2,898 views

1 answer to this question.

0 votes

Since tha bacpac file is not transactional, so when the bacpac is being generated, writing new rows to your target database will end up corrupting the index. The database should either have no other users, or it should be copied and a bacpac should be made from the copy.

1. Copy the target database (the database will take some time to copy), The following operation will create a full transactional copy:

CREATE DATABASE <name> AS COPY OF <original_name>

2. Find the status of your copy operation:

SELECT * FROM sys.dm_database_copies

3. Generate a bacpac file on the copied database, which isn't being used by anyone

4. Delete the copied database, and you'll have a working bacpac file

You can see the progress of the copy in their portal.

Hope it helps!

To know more about Azure, join Azure course today.

Thank you!!

answered Apr 2, 2019 by Prerna
• 1,960 points

Related Questions In Azure

0 votes
2 answers

How to restore SQL Server .bak file to Azure SQL Database?

To restore SQL Server .bak file you ...READ MORE

answered May 28, 2019 in Azure by sherry
• 140 points
33,614 views
+1 vote
1 answer

How to copy Azure SQL database to a local development server?

Actually, there are multiple ways to do ...READ MORE

answered Jul 9, 2018 in Azure by null_void
• 3,220 points
2,622 views
0 votes
1 answer

How can I copy SQL Azure database to a local development server?

There are certain ways to do this: Using SSIS ...READ MORE

answered Jun 26, 2018 in Azure by null_void
• 3,220 points
1,183 views
0 votes
1 answer

How can we connect Azure Web App to an Azure SQL Database?

Its easy now! Go to your Azure SQL ...READ MORE

answered Aug 9, 2018 in Azure by club_seesharp
• 3,450 points
6,801 views
0 votes
1 answer

How to install Windows Azure Storage Emulator?

There may be an issue with the ...READ MORE

answered Mar 7, 2019 in Azure by Prerna
• 1,960 points
2,789 views
0 votes
1 answer

Azure Storage Emulator shows error.

Check if you are running BitTorrent/uTorrent or similar ...READ MORE

answered Mar 16, 2019 in Azure by Prerna
• 1,960 points
1,709 views
0 votes
1 answer

Friendly filename when downloading Azure blob.

Azure blobs can be downloaded in four ...READ MORE

answered Mar 16, 2019 in Azure by Prerna
• 1,960 points
3,767 views
0 votes
1 answer

How to debug Azure 500 internal server error?

You can simply turn off custom error in ...READ MORE

answered Mar 29, 2019 in Azure by Prerna
• 1,960 points
4,844 views
0 votes
1 answer

How to query between databases in SQL Azure Database Server?

SQL Azure supports cross database queries: https://azure.microsoft.com/en-us/blog/querying-remote-databases-in-azure-sql-db/ Hope this ...READ MORE

answered Apr 9, 2019 in Azure by Prerna
• 1,960 points
13,003 views
0 votes
1 answer

How do disconnect to Azure SQL database if I can't access it?

Based on info  from Microsoft, I think ...READ MORE

answered Apr 26, 2019 in Azure by Prerna
• 1,960 points
1,342 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP