简体   繁体   English

在ASP.NET C中后台运行的应用程序

[英]Background running app in asp.net c#

I want to make a background running desktop app using asp.net c#. 我想使用asp.net c#创建后台运行的桌面应用程序。

The idea is to check a local database table and get all data from that table in order to insert all those data in live database table. 这个想法是检查本地数据库表并从该表中获取所有数据,以便将所有这些数据插入实时数据库表中。

If there is any better solution for that scenario please suggest me one. 如果在这种情况下有更好的解决方案,请给我推荐一个。

It seems that what you want to solve is moving data from multiple local databases into a central one so you can consume it via an asp.net website. 您似乎想要解决的问题是将数据从多个本地数据库移至一个中央数据库,以便您可以通过asp.net网站使用它。 I won't be discussing application part since that's an easy problem to solve once you can connect to a db that has all the data you need. 我将不讨论应用程序部分,因为一旦您可以连接到具有所需数据的数据库,这将是一个很容易解决的问题。

There are several things to consider here: 这里有几件事情要考虑:

  • Recurrence (one time migration vs continuous synchronization) 重复发生(一次迁移与连续同步)
  • Direction (do you need to sync one-way from local to central or two-way) 方向(您需要从本地同步到中央还是双向同步)
  • Data Contract (do local databases have same or different schema than central database) 数据合同(本地数据库与中央数据库具有相同或不同的架构)

    The Data Contract is your biggest problem if schemas are different since you will need to design at least a target schema for the central database that can take in data from local dbs. 如果架构不同,则数据合约是您最大的问题,因为您将需要为中央数据库设计至少一个目标架构,以便可以从本地dbs接收数据。 Even if schemas are identical, you will need to devise a way that data is partitioned in central database, you might need to introduce a sourceDatabaseId column in your tables so you won't have conflicting primary keys (you won't have this problems if your primary keys are guids) 即使架构相同,您仍需要设计一种在中央数据库中对数据进行分区的方法,您可能需要在表中引入sourceDatabaseId列,这样就不会出现冲突的主键(如果您的主键是Guid)

The others can be solved either building: 可以通过以下任一方法解决其他问题:

  1. A windows service - Inputs: periodicity (eg every hour), source db and target db connection strings. Windows服务-输入:周期性(例如每小时),源数据库和目标数据库连接字符串。 You will have a main loop that waits until time to run has come (based on periodicity) and fetches data from source db and saves them into target db (preferably in batches) 您将有一个主循环,等待直到运行时间到来(基于周期性),然后从源数据库中获取数据并将其保存到目标数据库中(最好成批保存)
  2. A console application - Inputs: source db and target db connection strings. 控制台应用程序-输入:源数据库和目标数据库连接字符串。 You will just move data in batches. 您将仅批量移动数据。 You can configure a Scheduled Task on the server that will perform scheduled runs of your console application to solve the periodic running part. 您可以在服务器上配置计划任务,该任务将执行控制台应用程序的计划运行,以解决定期运行的问题。

You would set up one such windows service or scheduled console app per local database. 您将为每个本地数据库设置一个这样的Windows服务或计划的控制台应用程序。

If you have complex databases you can look into tools like Microsoft Sync Framework to perform this data synchronization. 如果您有复杂的数据库,则可以使用Microsoft Sync Framework之类的工具来执行此数据同步。

您可以开发Windows服务来执行此类工作,并通过计时器设置将其安装在服务器上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM