14

I'm attempting to restore a backup (.bacpac) of a SQL Azure database to another SQL Azure database but am unable to do so because of 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 (I'll be attempting it again and will update with the exact error message shortly.

I've checked the live database and I can't see why this key is being violated.

I've also attempted to modify the model.xml contained in the .bacpac to remove the constraint but this fails because it now (rightly so) fails checksum validation.

4

1 回答 1

26

bacpac 文件不是事务性文件,因此在生成 bacpac 时写入目标数据库的新行最终会损坏索引。数据库必须没有其他用户连接进行写入,或者您可以复制数据库并从副本中制作 bacpac。

1)复制目标数据库,直接返回,但是数据库复制需要一些时间。此操作将创建一个完整的事务副本:

CREATE DATABASE <name> AS COPY OF <original_name>

2)查找您的复制操作的状态:

SELECT * FROM sys.dm_database_copies

3) 在复制的数据库上生成一个没有被任何人使用的 bacpac 文件。

4) 删除复制的数据库,您将拥有一个工作的 bacpac 文件。

于 2014-01-22T17:42:09.593 回答