Click here to Skip to main content
15,917,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 7-Jun-16 3:48am
v3
Comments
CHill60 6-Jun-16 10:38am    
You ask "tell me the best possible way of doing this" and then asked us to avoid the best ways of doing it!

What issues are you experiencing with your attempt to use MERGE - and how exactly did you try to use it?
Is this always only going to be a single table that needs to be synchronised?
Member 8057273 6-Jun-16 10:43am    
Ok,
I have updated the question with your concern. Can you please suggest a solution?
Member 8057273 6-Jun-16 10:45am    
Yes. I have out of many tables in source db, I need to update only 1 table in destination. I liked the concept of Merge but dont know how to make it work on two different servers. one is local while other is a remote IP address. The solution I felt good is :
MERGE TABLE1 as target
USING UTABLE as source
ON target.record_id = source.record_id
WHEN MATCHED THEN
UPDATE SET Target.columns=source.columns
CHill60 6-Jun-16 10:54am    
Well you can create the remote server as a Linked Server - see Linking Servers[^].
The query would then just need to fully specify the table i.e. [server].[database].[schema].[table]
Be aware that this may come with it's own performance issues - see Top 3 Performance Killers For Linked Server Queries - Thomas LaRock[^]
Member 8057273 6-Jun-16 11:03am    
Thanks for the response. But isn't there a way to mention source and destination server ips in the MERGE query? That would be an easy and clean shot.

1 solution

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
SQL
exec('your_SP_name') AT linked_server_name

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900