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 in Azure by sabby
• 4,350 points
111 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.

answered Apr 2 by Prerna
• 1,940 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 27 in Azure by sherry
• 140 points
4,994 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
198 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
65 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 8, 2018 in Azure by club_seesharp
• 3,450 points
159 views
0 votes
1 answer

How to install Windows Azure Storage Emulator?

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

answered Mar 6 in Azure by Prerna
• 1,940 points
136 views
0 votes
1 answer

Azure Storage Emulator shows error.

This blog might help with your query: http://blog.smarx.com/posts/windows-azure-storage-emulator-the-process-cannot-access-the-file-because-it-is-being-used-by-another-process Also, ...READ MORE

answered Mar 15 in Azure by Prerna
• 1,940 points
108 views
0 votes
1 answer

Friendly filename when downloading Azure blob.

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

answered Mar 15 in Azure by Prerna
• 1,940 points
50 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 in Azure by Prerna
• 1,940 points
243 views
0 votes
1 answer

How to query between databases in SQL Azure Database Server?

SQL Azure supports cross database queries: https://azure.micros ...READ MORE

answered Apr 9 in Azure by Prerna
• 1,940 points
76 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 in Azure by Prerna
• 1,940 points
65 views