如何用Microsoft.Sync解决"Storage Engine Operation Failed"?

How to resolve "Storage Engine Operation Failed" with Microsoft.Sync?

我开发了一个同步软件,可以使用 Microsoft Sync Framework 2.1 同步数据库和目录。

一段时间后,使用该应用程序的客户端收到此错误:

A storage engine operation failed with error code 25104 (HRESULT = 0x80004005, Source IID = {0C733A63-2A1C-11CE-ADE5-00AA0044773D}, Parameters=(4001, 0, 0, , , ,)).

我试图跟踪代码中的错误,但没有成功。

SyncOchestrator 开始同步时发生错误。从堆栈跟踪中我得到:

at Microsoft.Synchronization.Files.FileSyncProvider...ctor()

这是我的一些编码:

 try
        {
            // Set options for the sync operation
            FileSyncOptions options = FileSyncOptions.ExplicitDetectChanges |
                     FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecyclePreviousFileOnUpdates | FileSyncOptions.RecycleConflictLoserFiles;

            FileSyncScopeFilter filter = new FileSyncScopeFilter();
            filter.FileNameExcludes.Add("*.lnk"); // Exclude all *.lnk files
            filter.FileNameExcludes.Add("*.mdf"); // Exclude all *.mdf files
            filter.FileNameExcludes.Add("*.ldf"); // Exclude all *.ldf files
            filter.FileNameExcludes.Add("*.MDF"); // Exclude all *.MDF files
            filter.FileNameExcludes.Add("*.LDF"); // Exclude all *.LDF files
            filter.FileNameExcludes.Add("*.tdms_index"); // Exclude all *.tdms_index files

            Thread.Sleep(50);
            // Synchronization of 2 Folders
            FileSyncProvider providerA = new FileSyncProvider(Guid.NewGuid(), replica1RootPath, filter, options);
            FileSyncProvider providerB = new FileSyncProvider(Guid.NewGuid(), replica2RootPath, filter, options);
            providerA.DetectChanges();
            providerB.DetectChanges();

            Thread.Sleep(50);
            SyncOrchestrator agent = new SyncOrchestrator();
            agent.LocalProvider = providerA;
            agent.RemoteProvider = providerB;
            agent.Direction = SyncDirectionOrder.Upload;
            MessageBox.Show("Let's SYNC");
            agent.Synchronize(); // The error happens here

            Thread.Sleep(50);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
            MessageBox.Show(e.StackTrace);
        }

你能帮我解决这个问题吗?我越来越沮丧,我不知道我应该看哪里!该代码完美运行了一年。

更多信息:

我正在使用 C#,Microsoft.Synchronization 2.1,.Net 4,Visual Studio 2015。

非常感谢您的任何建议。

我终于想出了解决办法。碰巧元数据文件太大/已损坏。因此,为了解决我的问题,我对同步进行了分段,并一个一个地选择了所有子文件夹,而不是只选择一个包含 260 Go 文件的文件夹。

foreach (string dep in Directory.GetDirectories(plantFolder1)) // different departements
                            {
                                string depFolder1 = plantFolder1 + dep.Remove(0, plantFolder1.Length);
                                string depFolder2 = depFolder1.Replace(subReplica1, subReplica2); ;

                                Thread.Sleep(50);
                                // Synchronization of 2 Folders
                                FileSyncProvider providerA = new FileSyncProvider(Guid.NewGuid(), depFolder1, filter, options);

                                bool exists = Directory.Exists(depFolder2);
                                if (!exists)
                                    Directory.CreateDirectory(depFolder2);

                                FileSyncProvider providerB = new FileSyncProvider(Guid.NewGuid(), depFolder2, filter, options);
                                providerA.DetectChanges();
                                providerB.DetectChanges();

                                Thread.Sleep(50);
                                SyncOrchestrator agent = new SyncOrchestrator();
                                agent.LocalProvider = providerA;
                                agent.RemoteProvider = providerB;
                                agent.Direction = SyncDirectionOrder.Upload;
                                agent.Synchronize();
                                Thread.Sleep(50);
                            }

这就是我的问题的解决方案。希望对大家有所帮助。

谢谢。