简体   繁体   中英

Background running app in asp.net c#

I want to make a background running desktop app using 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. 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. 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)

The others can be solved either building:

  1. A windows service - Inputs: periodicity (eg every hour), source db and target db connection strings. 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.

If you have complex databases you can look into tools like Microsoft Sync Framework to perform this data synchronization.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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