简体   繁体   English

同步SQL Server Compact数据库以在C#中与在线数据库一起使用?

[英]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来注册和登录用户,则它应具有以下这些端点 (操作):

  • POST /users/register POST /用户/注册
  • GET /users/:id GET /用户/:ID
  • PUT /users/:id PUT /用户/:id
  • POST /users/login POST /用户/登录
  • DELETE /users/logout 删除/用户/注销

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: 回答以下问题可能会帮助您做出有意识的决定:

  • How many users will you have concurrently? 您将同时拥有几个用户?
  • How many items (DB records) will you have in the system? 系统中将有多少个项目(数据库记录)?

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: 参考文献:

  1. http://www.restapitutorial.com/ http://www.restapitutorial.com/
  2. https://github.com/interagent/http-api-design https://github.com/interagent/http-api-design
  3. http://mattgemmell.com/api-design/ http://mattgemmell.com/api-design/

Best regards and a happy new year, João 最好的问候和新年快乐,若昂

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

相关问题 C#SQL Server Compact数据库登录 - C# SQL Server Compact Database Login 将C#连接到SQL Server Compact数据库 - Connecting C# to SQL Server Compact database 使用sdf数据库(SQL Server Compact 3.5数据库文件)而不安装Microsoft sql server C# - Use sdf database(SQL Server Compact 3.5 database file) without installing Microsoft sql server C# 通过C#同步数据库SQL Server - Synchronising databases SQL Server via C# 如何在C#中使用SQL Server Compact将数据库架构复制到其他数据库? - Howto copy database schema to enother database using SQL Server Compact in C#? 记录已成功插入,但数据库未更新C#和SQL Server Compact数据库 - Record inserted successfully but database not updated C# and SQL Server Compact Database ClickOnce和SQL Server Compact数据库 - ClickOnce and SQL Server Compact database 如何使用C#在Windows窗体应用程序中的SQL Server Compact数据库中搜索? - How to Search in SQL Server Compact Database in windows form application using C#? 将记录插入到SQL Server CE数据库移动到另一个线程? C#Compact Framework 3.5 - Move record insert to SQL Server CE database into another thread? C# Compact Framework 3.5 将图像存储在SQL Server CE数据库C#Compact框架代码中 - Store an image in a SQL Server CE database C# Compact framework code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM