无法将 SQL Azure bacpac 导入 2016 CTP
Cannot import SQL Azure bacpac to 2016 CTP
我非常熟悉从 Azure SQL V12 导出到我的开发箱,然后导入到我的本地 sql (2014) 实例的过程。我正在启动一个新的 Win10 机器并安装了 SQL 2016 CTP。我正在连接到同一个 Azure 实例并可以对其进行操作——并且可以像 2014 一样导出 .bacpac。
但是当我尝试导入到本地时,我得到:
Could not import package.
Warning SQL72012: The object [FOO33_Data] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Warning SQL72012: The object [FOO33_Log] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
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_dbo.Address_dbo.User_idUser". The conflict occurred in database "FOO33", table "dbo.User", column 'idUser'.
Error SQL72045: Script execution error. The executed script:
PRINT N'Checking constraint: FK_dbo.Address_dbo.User_idUser [dbo].[Address]';
ALTER TABLE [dbo].[Address] WITH CHECK CHECK CONSTRAINT [FK_dbo.Address_dbo.User_idUser];
这个问题在MSDN上也有人提问和回答,所以在这里分享一下。
https://social.msdn.microsoft.com/Forums/azure/en-US/0b025206-5ea4-4ecb-b475-c7fabdb6df64/cannot-import-sql-azure-bacpac-to-2016-ctp?forum=ssdsgetstarted
来自链接答案的文本:
我怀疑这里出了什么问题,因为导出操作是使用在导出过程中发生变化的数据库实例执行的。这会导致导出的 table 数据不一致,因为与 SQL 服务器的物理 backup/restore 不同,导出不保证事务的一致性。相反,它们基本上是通过依次连接到数据库中的每个 table 和 运行 select * 来执行的。当两个table存在外键关系,读取的table数据不一致时,导致数据写入数据库后导入出错,导入代码尝试重新启用外键。建议使用数据库复制机制(create database copyDb as copy of originalDb),保证一个事务一致性的副本,然后从不变的数据库副本导出。
我非常熟悉从 Azure SQL V12 导出到我的开发箱,然后导入到我的本地 sql (2014) 实例的过程。我正在启动一个新的 Win10 机器并安装了 SQL 2016 CTP。我正在连接到同一个 Azure 实例并可以对其进行操作——并且可以像 2014 一样导出 .bacpac。
但是当我尝试导入到本地时,我得到:
Could not import package.
Warning SQL72012: The object [FOO33_Data] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Warning SQL72012: The object [FOO33_Log] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
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_dbo.Address_dbo.User_idUser". The conflict occurred in database "FOO33", table "dbo.User", column 'idUser'.
Error SQL72045: Script execution error. The executed script:
PRINT N'Checking constraint: FK_dbo.Address_dbo.User_idUser [dbo].[Address]';
ALTER TABLE [dbo].[Address] WITH CHECK CHECK CONSTRAINT [FK_dbo.Address_dbo.User_idUser];
这个问题在MSDN上也有人提问和回答,所以在这里分享一下。 https://social.msdn.microsoft.com/Forums/azure/en-US/0b025206-5ea4-4ecb-b475-c7fabdb6df64/cannot-import-sql-azure-bacpac-to-2016-ctp?forum=ssdsgetstarted
来自链接答案的文本:
我怀疑这里出了什么问题,因为导出操作是使用在导出过程中发生变化的数据库实例执行的。这会导致导出的 table 数据不一致,因为与 SQL 服务器的物理 backup/restore 不同,导出不保证事务的一致性。相反,它们基本上是通过依次连接到数据库中的每个 table 和 运行 select * 来执行的。当两个table存在外键关系,读取的table数据不一致时,导致数据写入数据库后导入出错,导入代码尝试重新启用外键。建议使用数据库复制机制(create database copyDb as copy of originalDb),保证一个事务一致性的副本,然后从不变的数据库副本导出。