用于SQL Server CE和SQL Server的Microsoft Sync Framework对列数据类型rea



我正在使用.NET Framework 4.6开发一个Winforms应用程序,该应用程序可以在线和离线运行。云数据库服务器是SQL server 2016,客户端将使用SQL server CE 4.0。

我打算使用Microsoft Sync框架来同步2台服务器之间的数据。

这是我的代码:

public static void Synchronize(string scopeName, string serverConnectionString, string clientConnectionString)
{
Initialize(scopeName, serverConnectionString, clientConnectionString);
Synchronize(scopeName, serverConnectionString, clientConnectionString, SyncDirectionOrder.UploadAndDownload);
CleanUp(scopeName, serverConnectionString, clientConnectionString);
}
private static void Initialize(string scope_name, string serverConnectionString, string clientConnectionString) 
{
// SQL Server Connection
SqlConnection serverConnection = new SqlConnection(serverConnectionString);
// Scope Description
DbSyncScopeDescription svrScopeDescription = new DbSyncScopeDescription(scope_name);
// Table List
ArrayList tablesList= new ArrayList {
"SYNC_TEST"
/* OTHER TABLES */
};
// Table/scope Descption
foreach (String table in tablesList) 
{
DbSyncTableDescription svrTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable(table, serverConnection);
svrTableDescription.Columns["PK"].IsPrimaryKey = true;
svrScopeDescription.Tables.Add(svrTableDescription);
}
// Apply SQL Server Scope Provision
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConnection, svrScopeDescription);
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
serverProvision.Apply();
// create a connection to the SyncCompactDB database
SqlCeConnection clientConn = new SqlCeConnection(clientConnectionString);
// get the description of Scope from the SyncDB server database
DbSyncScopeDescription clntScopeDescription = SqlSyncDescriptionBuilder.GetDescriptionForScope(scope_name, serverConnection);
// create CE provisioning object based on the Scope
SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, clntScopeDescription);
clientProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
// starts the provisioning process
clientProvision.Apply();
}
private static void Synchronize(string scopeName, string serverConnectionString, string clientConnectionString, SyncDirectionOrder syncDirectionOrder) 
{
try
{
// create a connection to the SyncCompactDB database
SqlCeConnection clientConn = new SqlCeConnection(clientConnectionString);
// create a connection to the SyncDB server database
SqlConnection serverConn = new SqlConnection(serverConnectionString);
// create the sync orchestrator
SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
// set local provider of orchestrator to a CE sync provider associated with the 
// ProductsScope in the SyncCompactDB compact client database
syncOrchestrator.LocalProvider = new SqlCeSyncProvider(scopeName, clientConn);
// set the remote provider of orchestrator to a server sync provider associated with
// the ProductsScope in the SyncDB server database
syncOrchestrator.RemoteProvider = new SqlSyncProvider(scopeName, serverConn);
// set the direction of sync session to Upload and Download
syncOrchestrator.Direction = syncDirectionOrder;
// subscribe for errors that occur when applying changes to the client
((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
// subscribe for errors that occur when applying changes to the server
((SqlSyncProvider)syncOrchestrator.RemoteProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
// execute the synchronization process
SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
// print statistics
Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
Console.WriteLine(String.Empty);
}
catch (Exception e) 
{
String x = e.Message;
String y = e.StackTrace;
String z = e.Source;
String x1 = e.InnerException.ToString();
String y1 = e.TargetSite.ToString();
String z1 = e.Data.ToString();
}
}
private static void dbProvider_SyncProcessFailed(object sender, DbApplyChangeFailedEventArgs e) 
{
throw new NotImplementedException();
}
private static void dbProvider_SyncProgress(object sender, DbSyncProgressEventArgs e) 
{
throw new NotImplementedException();
}
static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
{
// display conflict type
Console.WriteLine(e.Conflict.Type);
// display error message 
Console.WriteLine(e.Error);
}
private static void CleanUp(string scopeName, string serverConnectionString, string clientConnectionString) 
{
SqlConnection serverConnection = new SqlConnection(serverConnectionString);
SqlCeConnection clientConnection = new SqlCeConnection(clientConnectionString);
SqlSyncScopeDeprovisioning serverDeprovisioning = new SqlSyncScopeDeprovisioning(serverConnection);
SqlCeSyncScopeDeprovisioning clientDeprovisioning = new SqlCeSyncScopeDeprovisioning(clientConnection);
serverDeprovisioning.DeprovisionScope(scopeName);
serverDeprovisioning.DeprovisionStore();
clientDeprovisioning.DeprovisionScope(scopeName);
clientDeprovisioning.DeprovisionStore();
}

如果方向仅为下载,则效果良好。

然而,当我将方向更改为Upload、UploadDownload或DownloadUplaod时,对于数据类型real为float的每一列,我都会收到一个错误。

错误屏幕截图

有人能帮我解决一下我做错了什么吗?

我遇到了同样的问题。互联网上没有任何支持。当我从浮点转换为十进制时,它开始工作得很好。浮点被认为是近似/粗略的数据类型,十进制具有精确的精度,因此它有效。我甚至试过上面提到的图书馆dotmim,但它也不起作用。对此也没有太多支持。

相关内容

最新更新