如何创建将数据库表数据插入另一个数据库表的Windows服务。 [英] How to create windows service that on database table data insert into another database table.
问题描述
我有2个数据库
1:ADB
2:BDB
ADB包含3个ADBTabe / more fields
BDB包含3个字段的BDBTabe
当记录插入& quot; ADB.ADBTabe& quot;然后工作应该从该ADB表中获取数据并插入BDB.BDBTable
那么请您提供如何管理所有这些事情的方法。 />
我需要实现sql server DB端吗?
我如何为此实现Windows /任何其他工作?
能不能给我一个合适的建议。
我尝试了什么:
我不知道我是新的方案
I have 2 Databases
1: ADB
2: BDB
ADB contains ADBTabe with 3/more fields
BDB contains BDBTabe with 3 fields fields
When the records inserted into "ADB.ADBTabe" then the job should be take data from that ADB table and insert into BDB.BDBTable
So could you please provide the approach that how to manage all these things.
What i have to implement sql server DB side?
How can i implement Windows / Any other job for this?
Could you please give me the proper suggestion.
What I have tried:
I have no idea about the scenario i am new
推荐答案
写一个webservice(可以是WCF服务)将从BDB获取数据并将数据插入BD。(直接向前)
现在一旦更新ADB.ADBTabe然后触发通知webservice。它将从BDB获取数据并插入BD。
如果我有任何疑问,请告诉我。
Write a webservice(can be WCF service) which will fetch data from BDB and insert data into BD.(Straight forward)
Now as soon as you update ADB.ADBTabe then trigger a notification to webservice. It will will fetch data from BDB and insert into BD.
Let me know if I you have any doubt.
解决方案1:
默认创建一个列(比如updatedrow),这将是真的。如果您插入/更新新行,则将updatedrow设置为false为该记录。
解决方案2:
创建一个新表xyz它将保存新更新行的主键。之后使用表xyz中的主键移动数据。
解决方案3:运行多个查询来更新两个表,但它可能会降低应用程序性能。
Solution 1:
Create a column (say "updatedrow") by default which will be true. If you insert/update new row then set updatedrow to false for that record.
Solution 2:
Create a new table "xyz" which will hold primary key of newly updated row. later move the data by using primary keys present in the table xyz.
Solution 3: Run multiple queries to update both table, but it may degrade application performance.
我建议使用 SQL Dependency ,请参阅文章:
使用C# SQL依赖关系。 NET和SQL Server 2012 [ ^ ]
如果您有更新的SQL Server版本,也可以使用更改跟踪,请参阅:
表上的SQL Server更改跟踪(无触发器) [ ^ ]
May I suggest using SQL Dependency, see the article:
SQL Dependency with C#.NET and SQL Server 2012[^]
If you have a newer SQL Server version you can also use "Change tracking", see:
SQL Server Change Tracking on Table (Without Triggers)[^]
这篇关于如何创建将数据库表数据插入另一个数据库表的Windows服务。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!