本文介绍了使用C#同步远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C#同步SQL Server 2008中的两个数据库.
我在下面关注了这篇文章,但遇到了一些问题.
http://msdn.microsoft.com/en-us/library/ff928758 (v = SQL.110).aspx [ ^ ]

我可以在一台计算机上的两个数据库中获取它.
但是当我尝试同步位于不同计算机上的两个数据库时,在
出现了一些错误"SqlSyncScopeProvisioning clientProvision =新的SqlSyncScopeProvisioning(clientConn,scopeDesc);"

有人可以帮我吗?
非常感谢~~


这是我完整的代码.

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
//使用System.Windows.Forms;
使用System.Data;
使用System.Data.SqlClient;


使用Microsoft.Synchronization;
使用Microsoft.Synchronization.Data;
使用Microsoft.Synchronization.Data.SqlServer;


命名空间ProvisionClient
{
课程计划
{
静态void Main(string [] args)
{
SqlConnection clientConn =新的SqlConnection(@"Data
来源=.\\ SQLEXPRESS;初始目录= SyncExpressDB;
Trusted_Connection =是);


SqlConnection serverConn =新的SqlConnection("Data
来源= 192.168.8.45 \\ SQLEXPRESS,1433;
初始目录= SyncDB;
用户ID = sa;密码= 123);


DbSyncScopeDescription scopeDesc =
SqlSyncDescriptionBuilder.GetDescriptionForScope
("ProductsScope",serverConn);

错误在这里
====> SqlSyncScopeProvisioning clientProvision =新
SqlSyncScopeProvisioning(clientConn,scopeDesc);


clientProvision.SetCreateTableDefault
(DbSyncCreationOption.CreateOrUseExisting);

clientProvision.Apply();
}
}
}

I''m trying to synchronize two databases in SQL Server 2008 by using C#.
I followed this article below but I got some problems.
http://msdn.microsoft.com/en-us/library/ff928758(v=SQL.110).aspx[^]

I can obtain it within two databases on a single computer.
But when I was trying to synchronize two databases which were on different computers, I got some errors at
"SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);"

Could someone help me?
Thank you very much~~


This is my complete code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;


using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServer;


namespace ProvisionClient
{
class Program
{
static void Main(string[] args)
{
SqlConnection clientConn = new SqlConnection(@"Data
Source=.\\SQLEXPRESS; Initial Catalog=SyncExpressDB;
Trusted_Connection=Yes");


SqlConnection serverConn = new SqlConnection("Data
Source=192.168.8.45\\SQLEXPRESS,1433;
Initial Catalog=SyncDB;
User ID=sa;Password=123");


DbSyncScopeDescription scopeDesc =
SqlSyncDescriptionBuilder.GetDescriptionForScope
("ProductsScope", serverConn);

error is here
====> SqlSyncScopeProvisioning clientProvision = new
SqlSyncScopeProvisioning(clientConn, scopeDesc);


clientProvision.SetCreateTableDefault
(DbSyncCreationOption.CreateOrUseExisting);

clientProvision.Apply();
}
}
}

推荐答案




这篇关于使用C#同步远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:35