我尝试使用SQL Azure 数据同步在 SQL-Azure-DB 和本地 SQL-Server 2008R2 之间进行同步。
我只需要同步一张现在只有 90 行的表。Azure端的表有一个触发器集,但是我本地的sql-server上的表没有这个触发器(因为除了共享一个表,两个数据库没有任何共同点)。
当我尝试同步它失败并出现以下错误:
Sync failed with the exception "GetStatus failed with exception:
Sync worker failed, checked by GetStatus method.
Failure details:
An unexpected error occurred when applying batch file C:\Resources\directory\61e9d741c80a47b4ae195f835e62fcda.NTierSyncServiceWorkerRole.LS1\DSS_syncjobmxd24sznwfq5idekfaopaery\a0e8b11a-a08c-4081-b929-e3f80b70f045.batch.
See the inner exception for more details.
Inner exception:
Failed to execute the command 'BulkInsertCommand' for table 'dbo.tblUser';
the transaction was rolled back. Ensure that the command syntax is correct.
Inner exception:
SqlException Error Code: -2146232060 - SqlError Number:512,
Message: Subquery returned more than 1 value.
This is not permitted when the subquery follows =, !=, <, <= , >, >=
or when the subquery is used as an expression.
SqlError Number:3621,
Message: The statement has been terminated.
For more information, provide tracing id ‘bb8e3787-27c1-4b7e-9a26-6db2ff6724d3’ to customer support.
当我禁用触发器时,同步工作!
我的触发器:
CREATE TRIGGER [dbo].[UpdateUsersTable]
ON [dbo].[tblUser]
AFTER INSERT AS BEGIN SET NOCOUNT ON;
INSERT INTO [dbo].[Users] ([userID], [PartnerOrganizationId])
VALUES ((select [userID] from inserted), (select [country] from inserted))
END
作为一种方法,我认为可能是因为我的触发器和同步触发器以错误的顺序开始,所以我尝试了:
exec sp_settriggerorder @triggername = 'tblUser_dss_insert_trigger',
@order = 'first',
@stmttype = 'insert',
@namespace = null
exec sp_settriggerorder @triggername = 'UpdateUsersTable',
@order = 'last',
@stmttype = 'insert',
@namespace = null
go
但这并没有改变什么。还是同样的错误。
我是否有机会在启用触发器的情况下同步该表?