Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Sync Framework and SQL Server Compact

I develop a Windows C# application which can work in Online and Offline mode.
When in Online mode it connects to a SQL Server. In Offline mode it connects to a local DB.

I use the Microsoft Sync Framework 2.1 to sync the 2 databases on demand.

Until now I used a LocalDB instance of SQL Server as the local database. But it is a pain to setup the system automatically during the installation process of my application. So I tought to use SQL Server Compact 3.5 or 4.0 which is very easy to distribute (comes in a single file).

But I cannot get it to even compile the provisioning code of the Compact DB:

DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("MyScope");
SqlCeConnection clientConn = new SqlCeConnection(OfflineConnectionString);
var clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);
clientProvision.Apply();

which I used before (without the Ce classes) but SqlCeSyncScopeProvisioning cannot be resolved.

Something is terribly wrong here.
How can I sync my CompactDB to distribute this as my local database?

like image 362
juergen d Avatar asked Sep 18 '16 20:09

juergen d


People also ask

What is Microsoft Sync Framework Do I need it?

Microsoft Sync Framework is a comprehensive synchronization platform that enables collaboration and offline scenarios for applications, services, and devices. Using Microsoft Sync Framework, developers can build applications that synchronize data from any source using any protocol over any network.

Is SQL Server Compact deprecated?

In February 2013, Microsoft announced that SQL Server Compact Edition had been deprecated. Although no new versions or updates are planned, Microsoft will continue to support SQL Compact through their standard lifecycle support policy. Extended support for SQL Server Compact 4.0 ended on July 13, 2021.

What does Microsoft SQL Server Compact do?

Microsoft SQL Server Compact 4.0 is a free, embedded database that software developers can use for building ASP.NET websites and Windows desktop applications.


1 Answers

First ensure, you have successfully installed the sdk?

After this, make sure you have added the following references:

  • Microsoft.Synchronization.Data.dll,

  • Microsoft.Synchronization.Data.Server.dll

  • Microsoft.Synchronization.Data.SqlServer.dll
  • Microsoft.Synchronization.Data.SqlServerCe.dll

Also in my case it worked with adding

  • System.Data.SqlServerCe - 4.0

EDIT

Against your comment, this is only working if you use SQL Server CE 4.

I've tried it now with SQL Server CE 3.5 and indeed I could reproduce your issue.

Switching to SQL Server CE 4.0 fixed it.

ExampleTable 4.0

Table

TestCode

 var scopeDesc = new DbSyncScopeDescription("MyScope");
 var tbl = new DbSyncTableDescription("TestTable");
 var pkColumn = new DbSyncColumnDescription("Id", "int");
 pkColumn.IsPrimaryKey = true;
 tbl.Columns.Add(pkColumn);
 tbl.Columns.Add(new DbSyncColumnDescription("Name", "nvarchar(254)"));
 scopeDesc.Tables.Add(tbl);
 var clientConn = new SqlCeConnection(@"Data Source=test.sdf;Persist Security Info=False;");
 var clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);
 clientProvision.Apply();

Result

Everything compiles nicely. After following the above steps, you should be able to easily migrate your code to SQL Server CE

like image 122
lokusking Avatar answered Sep 18 '22 01:09

lokusking