如何在配置期间更改客户端架构?
我急于在我的项目的“离线支持”截止日期前启动并运行 Sync Framework(这从来都不是一件好事)。我们的服务器上有一个 SQL Express 2008 实例,然后将 SQLCE 部署到客户端。客户端仅与服务器同步,而不是点对点。
到目前为止,我已经完成了以下工作:
- 服务器模式设置
- 创建和测试范围
- 服务器配置
- 客户端配置和表创建
我对所有这些的相对简单性印象深刻。然后我意识到以下内容:
- 通过客户端配置到 SQLCE 创建的架构不会为 uniqueidentifier 类型设置默认值。
- FK 约束不在客户端上创建
这是用于创建客户端架构的代码(从我在网上找到的示例中提取)
static void Provision()
{
SqlConnection serverConn = new SqlConnection(
"Data Source=xxxxx, xxxx; Database=xxxxxx; " +
"Integrated Security=False; Password=xxxxxx; User ID=xxxxx;");
// create a connection to the SyncCompactDB database
SqlCeConnection clientConn = new SqlCeConnection(
@"Data Source='C:\SyncSQLServerAndSQLCompact\xxxxx.sdf'");
// get the description of the scope from the SyncDB server database
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(
ScopeNames.Main, serverConn);
// create CE provisioning object based on the scope
SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);
clientProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
// starts the provisioning process
clientProvision.Apply();
}
当 Sync Framework 在客户端上创建架构时,我需要进行前面列出的其他更改(默认值、约束等)。
这就是我感到困惑(和沮丧)的地方: 我遇到了一个代码示例,其中显示了具有CreatingSchema事件的SqlCeClientSyncProvider 。此代码示例实际上显示了在列上设置 RowGuid 属性,这正是我需要做的。但是,什么是 SqlCeClientSyncProvider?!这段时间(现在 4 天)我一直在我的同步代码中使用 SqlCeSyncProvider。那么有一个SqlCeSyncProvider和一个SqlCeClientSyncProvider吗?
MSDN 上的文档并没有很好地解释其中的任何一个。
我进一步困惑是否应该在配置时或同步时进行架构更改?
你们如何建议我在配置期间对客户端 CE 架构进行架构更改?
I'm rushing (never a good thing) to get Sync Framework up and running for a "offline support" deadline on my project. We have a SQL Express 2008 instance on our server and then will deploy SQLCE to the clients. Clients will only sync with server, no peer-to-peer.
So far I have the following working:
- Server schema setup
- Scope created and tested
- Server provisioned
- Client provisioned w/ table creation
I've been very impressed with the relative simplicity of all of this. Then I realized the following:
- Schema created through client provisioning to SQLCE does not setup default values for uniqueidentifier types.
- FK constraints are not created on client
Here is the code that is being used to create the client schema (pulled from an example I found somewhere online)
static void Provision()
{
SqlConnection serverConn = new SqlConnection(
"Data Source=xxxxx, xxxx; Database=xxxxxx; " +
"Integrated Security=False; Password=xxxxxx; User ID=xxxxx;");
// create a connection to the SyncCompactDB database
SqlCeConnection clientConn = new SqlCeConnection(
@"Data Source='C:\SyncSQLServerAndSQLCompact\xxxxx.sdf'");
// get the description of the scope from the SyncDB server database
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(
ScopeNames.Main, serverConn);
// create CE provisioning object based on the scope
SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientConn, scopeDesc);
clientProvision.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
// starts the provisioning process
clientProvision.Apply();
}
When Sync Framework creates the schema on the client I need to make the additional changes listed earlier (default values, constraints, etc.).
This is where I'm getting confused (and frustrated):
I came across a code example that shows a SqlCeClientSyncProvider that has a CreatingSchema event. This code example actually shows setting the RowGuid property on a column which is EXACTLY what I need to do. However, what is a SqlCeClientSyncProvider?! This whole time (4 days now) I've been working with SqlCeSyncProvider in my sync code. So there is a SqlCeSyncProvider and a SqlCeClientSyncProvider?
The documentation on MSDN is not very good in explaining what either of these.
I've further confused whether I should make schema changes at provision time or at sync time?
How would you all suggest that I make schema changes to the client CE schema during provisioning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SqlCeSyncProvider 和 SqlCeClientSyncProvider 是不同的。
后者通常称为脱机提供程序,这是 Visual Studio 中的本地数据库缓存项目项使用的提供程序。此提供程序与 DbServerSyncProvider 和 SyncAgent 配合使用,并在中心辐射型拓扑中使用。
您使用的提供商称为协作提供商或点对点提供商(也适用于中心辐射型场景)。 SqlCeSyncProvider 与 SqlSyncProvider 和 SyncOrchestrator 配合使用,并且没有相应的 Visual Studio 工具支持。
两个提供商都需要配置参与的数据库。
两种类型的提供程序以不同的方式提供跟踪和应用更改所需的同步对象。 SchemaCreated 事件仅适用于离线提供程序。第一次启动同步时以及当框架检测到尚未配置客户端数据库(创建用户表和相应的同步框架对象)时,会触发此获取。
其他提供商使用的范围配置不应用除 PK 之外的约束。因此,您必须执行配置后步骤,以便在框架之外自行应用默认值和约束。
SqlCeSyncProvider and SqlCeClientSyncProvider are different.
The latter is what is commonly referred to as the offline provider and this is the provider used by the Local Database Cache project item in Visual Studio. This provider works with the DbServerSyncProvider and SyncAgent and is used in hub-spoke topologies.
The one you're using is referred to as a collaboration provider or peer-to-peer provider (which also works in a hub-spoke scenario). SqlCeSyncProvider works with SqlSyncProvider and SyncOrchestrator and has no corresponding Visual Studio tooling support.
both providers requires provisioning the participating databases.
The two types of providers provisions the sync objects required to track and apply changes differently. The SchemaCreated event applies to the offline provider only. This get's fired the first time a sync is initiated and when the framework detects that the client database has not been provisioned (create user tables and the corresponding sync framework objects).
the scope provisioning used by the other provider dont apply constraints other than the PK. so you will have to do a post-provisioning step to apply the defaults and constraints yourself outside of the framework.
在研究不使用 SyncAgent 的解决方案时,我发现以下方法也可以工作(除了上面我评论的解决方案之外):
While researching solutions without using SyncAgent I found that the following would also work (in addition to my commented solution above):