一个客户数据库与中央数据库同步 [英] Synchronize a client database with the central database

查看:199
本文介绍了一个客户数据库与中央数据库同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新现有数据或从客户数据库中插入新的数据说,DB1到中央数据库DB2说既保持相同的架构和两个数据库驻留在同一台机器上。该更新不biderectional。我只是想改变从客户端(DB1)服务器(DB2)反映。

I need to update existing data or insert new data from client database say DB1 into central database say DB2 both holding same schema and both databases reside in same machine. The updates are not biderectional. I just want changes to be reflected from client(DB1) to server(DB2).

客户机数据库(DB1)只不过是连接到同一服务器的中央数据库(DB2)存在备份数据库(全数据库备份选自MDF和LDF文件的)。我不会做任何更改到备份数据库(DB1)一旦连接到服务器。备份数据库(DB1)已经有,我想将它更新到中央数据库(DB2)修改后的数据。所以,我该怎么做编程方式使用C#.NET?。可你给任何例如code?

The client database(DB1) is nothing but the backup database(Full database backup consisting of mdf and ldf files) which is attached to the same server where the central database(DB2) exists. I am not going to make any changes to the backup database(DB1) once it is attached to the server. The backup database(DB1) already has the modified data which i want to update it to central database(DB2) . So how do i do programatically using C# .NET?.Can you give any example code?

我曾尝试与推送订阅事务复制不发送快照。问题是,我想在第一枪更新从DB1到中央数据库DB2修改后的数据本身,而是事务复制不允许我这样做。它不会发送任何修改的数据这已经是美元的DB1 p $ psent。所以,当您尝试发送,而不快照的初始数据present DB1中是不变。备份数据库(DB1)已经有之前复制修改后的数据。我要如何解决这个,因为我不打算插入任何新的或修改的数据到备份数据库(DB1)后,我设置的复制。

I have tried transactional replication with push subscription without sending the snapshot. The problem is that the i want to update the modified data from DB1 to central database DB2 at the first shot itself but transactional replication will not allow me to do so. It will not send any modified data which is already present in DB1. So the initial data present in DB1 is untouched when you try to send without snapshot. The backup database (DB1) already has the modified data prior to replication. How do i tackle this as i am not going to insert any new or modify data into the backup database(DB1) after i set replication.

感谢和问候, 帕

推荐答案

要做到这一点,你有以下几种选择:

To achieve this you have the following options:

1)使用SQL Server事务复制。让DB1作为出版商,DB2作为认购人,去拉或推基于订阅的。在DB1所有更改都将只是反映到中央。如果中央对同一元组的任何变化,我们在那里,他们将DB1的变化被改写。

1.) Use SQL Server Transactional Replication. Make DB1 as Publisher, DB2 as Subscriber and go for Pull or Push based subscription. All changes in DB1 will be simply reflected to central. If any changes we there in Central for the same tuple, they will be overwritten by DB1 changes.

优点:易于实施和可靠 缺点:很少定制

Advantages: Easy to implement and reliable Disadvantages: Very little customization

2)使用微软同步框架SQLDataBaseProvider。 优点:非常灵活 缺点:我已经听说了不好的事情,但从来没有尝试过

2.) Use Microsoft Sync Framework SQLDataBaseProvider. Advantages: Very Flexible Disadvantages: I have heard bad things about it but never tried.

3)定制的实现:这是一个有点辛苦,因为你需要跟踪DB1的变化。一个选项可以读取事务日志,该事务复制内部做或另一种选择是使用触发器和构建变化的知识。然后,你需要写一个图书馆或程序,这将让你改变的知识那么它将适用于中央。

3.) Custom Implementation: This is a bit hard as you need to track changes on DB1. One option can be reading transactional logs which Transactional Replication does internally or other option is to use trigger and build knowledge of changes. Then you need to write a library or routine which will get you change knowledge then it will apply to central.

编辑: 对于备份和恢复progmatically数据库:

For backup and restore database progmatically:

http://www.mssqltips.com/tip.asp?tip=1849

这篇关于一个客户数据库与中央数据库同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆