开发者

Sync services not actually syncing

开发者 https://www.devze.com 2022-12-24 17:32 出处:网络
I\'m attempting to sync a SQL Server CE 3.5 database with a SQL Server 2008 database using MS Sync Services. I am using VS 2008. I created a Local Database Cache, connected it with SQL Server 2008 and

I'm attempting to sync a SQL Server CE 3.5 database with a SQL Server 2008 database using MS Sync Services. I am using VS 2008. I created a Local Database Cache, connected it with SQL Server 2008 and picked the tables I wanted to sync. I selected SQL Server Tracking. It modified the database for change tracking and created a local copy (SDF) of the data.

I need two way syncing so I created a partial class for the sync agent and added code into the OnInitialized() to set the SyncDirection for the tables to Bidirectional. I've walked through with the debugger and this code runs.

Then I created another partial class for cache server sync provider and added an event handler into the OnInitialized() to hook into the ApplyChangeFailed event. This code also works OK - my code runs when there is a conflict.

Finally, I manually made some changes to the server data to test syncing. I use this code to fire off a sync:

var agent = new FSEMobileCacheSyncAgent();
var syncStats = agent.Synchronize();

syncStats seems to show the count of the # of changes I made on the server and shows that they were applied. However, when I open the local SDF file none of the changes are there.

I basically followed the instructions I found here:

http://msdn.microsoft.com/en-us/library/cc761546%28SQL.105%29.aspx

and here:

http://keithelder.net/blog/archive/2007/09/23/Sync-Services-for-SQL-Server-Compact-Edition-3.5-in-Visual.aspx

It seems like this should "just work" at this point, but the changes made on the server aren't in the local SDF file. I guess I'm missing something but I'm just not seeing it right now.

I thought this might be because I appeared to be using version 1 of Sync Services so I removed the references to Microsoft.Synchronization.* assemblies, installed the Sync framework 2.0 and added the new version of the assemblies to the project. That hasn't made any difference.

Ideas?

Edit: I wanted to enable tracing to see if I could track this down but the only way to do that is through a WinForms app since it requires entries in the app.config file (my original project was a class library). I created a WinForms project and recreated everything and suddenly everything is working. So apparently this requires a WinForm project for some reason?

This isn't really how I planned on using this - I had hoped to kick off syncing through another non-.NET application and provide the UI there so the experience was a bit more seemless to the end user. If I can't do that, that's OK, but I'd really like to know if/how to make this work as开发者_运维知识库 a class library project instead.


You can load a dll's config file this way (in your class' constructor):

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", System.IO.Path.Combine(Environment.CurrentDirectory, "<dll name>.config"));
System.Configuration.ConfigurationManager.RefreshSection("configuration");


The senario you describe should work. I have a similar app that used the sync inside a class, and thats ok.. You do need to be able to set the trace properties, most easily through a app.config, but thats not your problem... No errors reported by the Syncronize method?

No Conflict errors raised?

If you are still having difficulty you can add the following bits to your applications config file, in the section

   <switches>
      <add name="DefaultSwitch" value="Information" />
      <!-- Sync Tracer Setting 0-off, 1-error, 2-warn, 3-info, 4-verbose. -->
      <add name="SyncTracer" value="4" />
    </switches>

    <trace autoflush="true">
      <listeners>
        <add name="TestSyncListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\SyncTraceFile.txt" />
      </listeners>
    </trace>

Then have a look in the c:\SyncTraceFile.txt for any issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消