使用本地数据库更新远程数据库 [英] Keep remote database updated with local database

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

问题描述

您好。我在源代码中使用MSSQL 2008 Express和VS Express 2010中的c#.net express版本。

我有一个远程数据库和一个本地数据库。

我想保留远程数据库表,其中一个源数据库表已更新。

实现复制,tablediff,第三方工具,微软同步等是时间过长而且还需要一些直接不属于某些工具的工具快递版。

我正在寻找一个简单的解决方案。

点击完成更新的按钮将放在软件中并由新手用户使用。 />
我打算在内联查询或存储过程中使用MERGE,但无法取得成功。如果在两个连接上触发查询的主要问题。

即从本地读取并发送到远程服务器。

另外,我不想删除远程数据然后重新 - 在每个更新作业上使用sqlbulkcopy或其他方法复制数据。这将消耗太多的时间和服务器带宽。

请帮助。



我尝试过: < br $>


Sqlbulkcopy同步,合并,存储过程。

MERGE TABLE1作为目标

使用UTABLE作为源

ON target.record_id = source.record_id

当匹配时

UPDATE SET Target.columns = source.columns

I不知道如何将源作为本地服务器和目标作为远程服务器

Hi. I am using MSSQL 2008 Express at source with c#.net express edition in VS express 2010.
I have a remote database and a local database.
I want to keep the table of remote database with one table of source database updated.
Implementing Replication, tablediff, third party tools, microsoft sync, etc. is too time taking and also needs some tools that are directly not the part of express edition.
I am looking for a simple solution.
The button clicking on which updation is done will be placed inside a software and used by a novice user.
I am planning to use MERGE in inline query or in stored procedure but not able to achieve success. The main issue if firing queries on two connections.
i.e., reading from local and sending to remote server.
Also, I donot want to delete the remote data and then re-copy data using sqlbulkcopy or other method on every updation job. It will consume too much time and server bandwidth.
Kindly help.

What I have tried:

Sqlbulkcopy Sync, Merge, stored procedure.
MERGE TABLE1 as target
USING UTABLE as source
ON target.record_id = source.record_id
WHEN MATCHED THEN
UPDATE SET Target.columns=source.columns
I donot know how to make source as local server and target as remote server

推荐答案

另请参阅上面的评论。



好​​的,MERGE语句的目标不能是远程表,但源可以是。



我建议在目标(即远程)服务器上的存储过程中设置MERGE语句。然后,您可以使用
See also the reams of comments above.

Ok, the target of a MERGE statement cannot be a remote table, but the source can be.

I suggest setting up the MERGE statement in a Stored Procedure on the target (i.e. remote) server. You can then execute it from your source / button press using
exec('your_SP_name') AT linked_server_name



参考: EXECUTE(Transact-SQL) [ ^ ]

这里有另一个例子 - 动态SQL的诅咒和祝福 [ ^ ] - 使用带动态SQL的参数来运行传递查询。


Reference: EXECUTE (Transact-SQL)[^]
There is another example here - The Curse and Blessings of Dynamic SQL[^] - using parameters with dynamic SQL to run the pass-through query.


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

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