[英]Synchronising SQL Server Compact database to work with an online database in C#?
I am creating a desktop application and the users would like to view information from the application online, on a website that I would create. 我正在创建一个桌面应用程序,用户希望在我要创建的网站上在线查看该应用程序中的信息。
The problem is my application is using SQL Server Compact as the database. 问题是我的应用程序正在使用SQL Server Compact作为数据库。 I really need help on how to create a web service that can get data from the local desktop application.
我真的需要有关如何创建可从本地桌面应用程序获取数据的Web服务的帮助。 The users (aka admin of the app) should also be able to make changes from the website that would affect the app.
用户(即应用程序的管理员)也应该能够从网站上进行更改,从而影响应用程序。 They also want to see information such as inventory, contact, etc from the app on the website.
他们还希望从网站上的应用程序查看库存,联系方式等信息。
I have created the desktop app but have no clue on creating the web app / service or synchronizing the local database to the online one. 我已经创建了桌面应用程序,但是对创建Web应用程序/服务或将本地数据库同步到在线数据库一无所知。
First of all, do you really need to have a local database and to keep it in sync with the online one? 首先,您真的需要一个本地数据库并使它与在线数据库保持同步吗? As far as I understood, you'll develop both of them so you'll have the control.
据我了解,您将同时开发它们,因此您将拥有控制权。 Therefore the first logical step I see here is to create a REST API [1,2,3] and provide end-points both to read and write from your online database.
因此,我在这里看到的第一个逻辑步骤是创建REST API [1,2,3],并提供可从您的在线数据库读取和写入的端点 。 For instance, if you want to build a simple API to register and login users, it should have at these end-points (operations):
例如,如果您想构建一个简单的API来注册和登录用户,则它应具有以下这些端点 (操作):
So you can register a new user, see the data in his profile and be able to update it and, of course, log-in and log-out . 因此,您可以注册一个新用户,查看其个人资料中的数据并能够对其进行更新,当然也可以进行登录和注销 。
Now both your online and desktop applications can be clients of the API. 现在,您的在线和桌面应用程序都可以成为API的客户端。 You can add, edit and remove products in one of them and the changes will appear in the other one as well.
您可以在其中一个产品中添加,编辑和删除产品,更改也将在另一个产品中显示。 Of course I am making some assumptions here (no need to have real-time updates, desktop client can have a always on connection, the size of the response payloads are not huge, etc).
当然,我在这里做了一些假设(无需进行实时更新,桌面客户端可以保持始终连接,响应有效负载的大小不大,等等)。
If you need to have a local database anyway, you can have a field updatedAt in the tables you want to be in sync so the desktop application can query the API only to get the changes produced after a given date, decreasing the payload of the API response (and the bandwidth used, if that matters). 如果仍然需要本地数据库,则可以在要同步的表中有一个updateAt字段,以便桌面应用程序只能查询API以获取给定日期后产生的更改,从而减少了API的有效负载响应(以及所使用的带宽,如果有关系的话)。 Anyway, I think this step is an optimization to the real problem, so you might only think in all of this (having a local DB, keeping track of the changes and syncing...) after you thought carefully about the API and the clients first.
无论如何,我认为此步骤是对实际问题的优化,因此,在仔细考虑了API和客户端之后,您可能只会考虑所有这些(拥有本地数据库,跟踪更改并进行同步...)。第一。 Answering the following questions probably can help you to take a conscious decision:
回答以下问题可能会帮助您做出有意识的决定:
If the answer is less than 100 users and a thousand of records, you probably should not worry about synchronization. 如果答案少于100个用户和上千条记录,则您可能不必担心同步。 However we can only help you with more information about the requirements of the system.
但是,我们只能为您提供有关系统要求的更多信息。
References: 参考文献:
Best regards and a happy new year, João 最好的问候和新年快乐,若昂
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.