locked
MS SYNC PerformCleanup RRS feed

  • Question

  • Hello

    I use this code to cleanup the tombstone rows from tracking tables.

    private SqlCeSyncStoreMetadataCleanup _localMetadataCleanup;
    private void PerformLocalCleanup()
    {
        try
        {
    		_posLog.Info("Perform cleanup for LOCAL database.");
    
    		using (var localSqlConnection = new SqlCeConnection(DBContextFactory.ConnectionString))
    		{
    			if (_localMetadataCleanup == null)
    			{
    				_localMetadataCleanup = new SqlCeSyncStoreMetadataCleanup(localSqlConnection);
    			_	localMetadataCleanup.RetentionInDays = 7;//wait 7 days before deletion
    			}
    			var result = _localMetadataCleanup.PerformCleanup();
    		}
        }
        catch (Exception ex)
        {
    		_posLog.Error(ex, "Perform cleanup for LOCAL database failed.");
        }
    }

    Lately I have discovered an error in my log files and I cannot figure why:

    Perform cleanup for LOCAL database failed.
    Message: Cannot access a disposed object.
    Object name: 'SqlCeConnection'.
    Type   : System.ObjectDisposedException
    Stack  :    at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
      at System.Data.SqlServerCe.SqlCeConnection.Open()
      at Microsoft.Synchronization.Data.SyncUtil.OpenConnection(IDbConnection connection)
      at Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncSchemaInfoHandler.ReadSyncSchemaInfo(IDbConnection connection, IDbTransaction transaction, String objectPrefix, String objectSchema)
      at Microsoft.Synchronization.Data.SyncSchemaInfoHandlerBase.ReadSyncSchemaInfo(IDbConnection connection, String objectPrefix, String objectSchema)
      at Microsoft.Synchronization.Data.SqlServerCe.SqlCeManagementUtils.VerifyRuntimeAndSchemaVersionsMatch(SqlCeConnection connection, SqlCeTransaction trans, String objectPrefix, Boolean autoUpgrade, Boolean throwWhenNotProvisioned)
      at Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncStoreMetadataCleanup.PerformCleanup()
      at POS.PosPosSync.Local.PosPosSyncService.PerformLocalCleanup()
    Source : System.Data.SqlServerCe
    Target : Void Open(Boolean)

    Any ideas?

    Angela

    Wednesday, October 1, 2014 8:22 AM

Answers

  • the first time you call PerformLocalCleanup(), _localMetadataCleanup get's initialized with a connection. The subsequent  call to PerformLocalCleanup will find _localMetadataCleanup  not equal to null, so it proceeds to PerformCleanup(). that fails because the original connection you set on first call is no longer there.
    Thursday, October 2, 2014 1:08 AM