SQL Server2005数据同步
本文出自我的个人网站【思考者日记】,转载请务必保留此出处。SQLServer2005中对于增、删、改和查询是有某些冲突的,很容易造成死锁。现在有台数据库里的FileDet
本文出自我的个人网站【思考者日记】,转载请务必保留此出处。
SQL Server2005中对于增、删、改和查询是有某些冲突的,很容易造成死锁。现在有台数据库里的FileDetail表是由两套程序来操作的,一套程序负责增、删、改,另一套程序负责查询,结果当数据量大的时候,很容易造成查询的那套程序查询数据很慢,甚至造成死锁的情况。原因是SQL Server2005里的设计机制是插入的时候,死锁的记录只会是某一条,并不影响下一条和上一条,但是纠结的情况来了,你插入的时候是爽了,并不影响你,可是当我查询的时候,如果发现某一条记录被死锁,服务器空间,那么我这条T-SQL查询的结果就是全部死锁,查询不出任何东西。
为了解决这个问题,我们可以使用同步来解决这个问题,将这台数据库分开,我们建立两个FileDetail表,一个用来给增、删、改的程序使用,另一个给查询的程序来调用,这样就可以解决以上的难题。
在SQL Server2005中,同步数据需要:发布服务器、分发服务器和订阅服务器,源数据所在的服务器是发布服务器,负责发表数据。发布服务器把要复制的数据或对象发生的改变复制到分发服务器,分发服务器用来接收数据的所有改变,它包含一个分发数据库,并保存这些改变,再把这些改变分发给订阅服务器。在复制过程中,发布服务器是一种数据库实例,它通过复制向其他位置提供数据,分发服务器也是一种数据库实例,它起着存储区的作用。订阅服务器是接收复制数据的数据库实例。一个订阅服务器可以从多个发布服务器上接收数据。
下面的例子因为我现在没有那么多资源,只用了本机做测试,我还测试了两台之间的操作,大家有兴趣的可以弄多台来试试。
现在我们来通过SQL Server2005来实现数据同步:
首先我们开启SQL Server代理(默认是禁用的)
正在启动——》启动成功
现在我们来复制下数据库。
点击siccdb右键-任务-复制数据库,出现以下界面
下一步
这里使用SQL Server身份验证,一般建议大家都用这种方式,安全,不会出错。填好之后,下一步。
这里的目标服务器也使用SQL Server身份验证。如果你想使用同一网段下别的计算机的数据库,那么这里的目标服务器可以选择你的远程计算机,注意:远程计算机连接不支持IP和别名,必须使用DoMain登录名(即域计算机登录名)。这里说下我在测试两台计算机同步碰到的问题,我发现登录不了了?
原因
你的计算机改过计算机名
可以使用
SELECT * FROM Sys.SysServers来查询下数据库里的源服务器名
我这里是WILCOM-DEV_SQLS
我们ping下服务器的IP地址,远程登录不上的可以在C:WINDOWSsystem32driversetc下的hosts文件里配置下
下一步:
这里大家可以根据实际情况来选择,默认是第一种,我这里选择第二种,香港服务器租用,因为我的源数据库是不能断开的(断开了就要出大事了,呵呵,开个玩笑)好了,废话不多说,选中后点下一步:
这里默认会勾选你要发布的数据库,状态必须是已存在于目标上才可以发布。好了,我这里没有问题,下一步:
这里是目标数据库,我给改了下目标数据库的名字为siccdb_bak
下面选择如果目标数据库已存在的情况,我选择第一种,下一步。
这里大家可以不要动,保持默认就好。直接下一步
我这里就不选择计划了,大家可以自己试试看计划的执行状态。
如果你发现下面的integration Services代理账号不让选,是灰色的禁止状态,那建议你看下你的SQL Server服务有没有安装这个,如果没有,那悲催了,你就重新运行SQL Server的安装向导重新安装下这个服务吧。(下图的这个服务)
紧接着,下一步
这里就可以完成啦。
OK,复制完毕。
刷新下数据库,我们会发现多了一个siccdb_bak
现在,我们来进行发布这个siccdb数据库,让siccdb_bak来保持和它同步。
选择数据库同级目录下的复制-本地发布-新建发布,启动发布向导。
下一步:
默认第一个,下一步。
这里是存放快照文件的目录,大家默认即可, 免的后面找不到。下一步:
这里我们选择需要发布的数据库,下一步:
这里我们选择快照发布,其他的选项大家可以对照上图中的说明来自己尝试,相信大家都很聪明滴。下一步:
这里我们展开表,可以发现这个库下的所有表,香港服务器,我们可以根据情况来勾选,好了,下一步:
这里我们还可以对选中的表添加SQL语句来筛选,因为我这里用不到,就不给大家做演示了,节约时间,赶紧写教程。下一步:
这里我们需要勾选立即和计划,勾选计划后,我们选择更改
我这里需要实时同步,所以我选择了每天每分钟来进行同步,大家可以根据实际情况来选择,好了,确定。
好了,现在来检查下是否是你选择的计划,下一步:
这里选择安全设置,
上面的信息我在前面已经说过了,如果不知道的,可以参考我前面的说明。填好后,确定。
下一步:
立即发布,下一步:
这里填好发布名称,完成。
OK,一切正常,我们关闭。
本地发布下多了一个[siccdb]:TOB就是我们刚创建的发布,现在我们需要来订阅它,右键本地订阅-新建订阅:
打开订阅向导,下一步:
这里找到了我们的发布源,下一步:
这里选择[推送订阅],简单点,不耽误时间了,下一步:
这里我们选择好订阅服务器和订阅数据库,下一步:
这里我们选好与分发服务器、与订阅服务器的连接:
填好后,确定。
选择连续运行,下一步:
选择连续运行,下一步:
创建订阅,下一步:
好了,这里就完成了。
现在我们在siccdb中增、删、改些数据,我们在一分钟后会发现,siccdb_bak中也同步更新了这些数据。
本文出自我的个人网站【思考者日记】,转载请务必保留此出处。
本文出自 “On My Way” 博客,请务必保留此出处

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.
