Transactions 同步框架-如何在同步事务中启用和禁用唯一索引?
我想在同步事务中禁用并重建唯一索引。能做到吗Transactions 同步框架-如何在同步事务中启用和禁用唯一索引?,transactions,constraints,microsoft-sync-framework,Transactions,Constraints,Microsoft Sync Framework,我想在同步事务中禁用并重建唯一索引。能做到吗 表中有多行需要更改,但更新的值违反了唯一索引。但是,在更改所有行之后,约束将得到满足,因此我希望在同步过程结束之前禁用此索引。如果您不更改唯一索引,则无需执行此操作 使用SQL Server 2008,您可以执行联机重组或重建: 您想做什么?如果不更改唯一索引,则无需这样做 使用SQL Server 2008,您可以执行联机重组或重建: 您想做什么?如果任何人对类似问题的解决方案感兴趣,您可以通过附加到同步提供程序的某些事件来控制同步期间
表中有多行需要更改,但更新的值违反了唯一索引。但是,在更改所有行之后,约束将得到满足,因此我希望在同步过程结束之前禁用此索引。如果您不更改唯一索引,则无需执行此操作 使用SQL Server 2008,您可以执行联机重组或重建:
您想做什么?如果不更改唯一索引,则无需这样做 使用SQL Server 2008,您可以执行联机重组或重建:
您想做什么?如果任何人对类似问题的解决方案感兴趣,您可以通过附加到同步提供程序的某些事件来控制同步期间使用的事务:
private void DbCacheServerSyncProvider_ApplyingChanges(object sender, ApplyingChangesEventArgs e)
{
if (e.Transaction == null)
{
e.Transaction = e.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
DisableConstraints(e.Connection, e.Transaction);
}
}
private void DbCacheServerSyncProvider_ChangesApplied(object sender, ChangesAppliedEventArgs e)
{
if (e.Transaction != null)
{
EnableConstraints(e.Connection, e.Transaction);
e.Transaction.Commit();
e.Transaction.Dispose();
}
}
private void DbCacheServerSyncProvider_ApplyChangeFailed(object sender, ApplyChangeFailedEventArgs e)
{
if (e.Transaction != null)
{
e.Transaction.Rollback();
e.Transaction.Dispose();
}
throw new InternalException("Server-side conflict has occurred during synchronization. Conflict details:\r\n" + SyncUtils.CreateChangeFailedDetails(e).Trim('\r', '\n'));
}
如果任何人对类似问题的解决方案感兴趣,可以通过附加同步提供程序的某些事件来控制同步期间使用的事务:
private void DbCacheServerSyncProvider_ApplyingChanges(object sender, ApplyingChangesEventArgs e)
{
if (e.Transaction == null)
{
e.Transaction = e.Connection.BeginTransaction(IsolationLevel.ReadCommitted);
DisableConstraints(e.Connection, e.Transaction);
}
}
private void DbCacheServerSyncProvider_ChangesApplied(object sender, ChangesAppliedEventArgs e)
{
if (e.Transaction != null)
{
EnableConstraints(e.Connection, e.Transaction);
e.Transaction.Commit();
e.Transaction.Dispose();
}
}
private void DbCacheServerSyncProvider_ApplyChangeFailed(object sender, ApplyChangeFailedEventArgs e)
{
if (e.Transaction != null)
{
e.Transaction.Rollback();
e.Transaction.Dispose();
}
throw new InternalException("Server-side conflict has occurred during synchronization. Conflict details:\r\n" + SyncUtils.CreateChangeFailedDetails(e).Trim('\r', '\n'));
}