良好的C#.NET解决方案来管理频繁的数据库查询 [英] Good C#.NET Solution to manage frequent database polling

查看:548
本文介绍了良好的C#.NET解决方案来管理频繁的数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的工作对将超过通过WCF和WCF数据服务的网络进行通信与数据库的C#.NET桌面应用程序。将有可能需要在一定的时间间隔被刷新的应用中有许多斑点。最简单的解决办法是只是把一个计时器这些领域,并重新查询数据库。然而,随着数千客户连接到服务层,因此数据库中,这些操作将是服务器非常昂贵的。

I am currently working on a c# .NET desktop application that will be communicating to a database over the internet via WCF and WCF Data Services. There will be many spots in the application that may need to be refreshed upon some interval. The easiest solution would be to just put these areas on a timer and requery the database. However, with thousands of clients connecting to the service layer and hence database, these operations would be very expensive to the server.

我所考虑的是建立一个RSS feed的由客户机轮询,并让客户知道何时这些特定区域需要进行更新。 RSS提要将由服务,要么轮询数据库的变化,或通过由由客户端的WCF请求排队的项的列表迭代

What I have considered is creating an RSS feed that is polled by the client, and lets the client know when these particular areas need to be updated. The RSS feed will be managed by a service that either polls the database for changes, or iterates through a list of items that are queued up by the WCF requests made by the client.

我也曾考虑创建一个从客户端到服务器的一些直接和持续的连接,但我不知道是什么出站防火墙端口会从客户端开放。我大概只算端口80/443。

I have also considered creating some direct and continuous connection from the client to the server, but I am not sure what outbound firewall ports would be open from the client. I could probably only count on port 80/443.

所以我的问题是什么样的解决方案已经人不得不成功实施来解决这个问题?曾经做过的人RSS? Microsoft同步服务?对一些客户端和服务器之间的双向通信通过WCF保存端口?

So my question is what solutions have people had success implementing to solve this problem? Have people done RSS? Microsoft Sync Services? Two way communication between client and server over some save port via WCF?

任何想法是极大的赞赏。

Any ideas are greatly appreciated.

推荐答案

我想你可能想要去的两种方法的结合。首先,你可以使用长轮询从客户机到服务器,使服务器可以通知只要改变客户端时,客户端有兴趣

I think you might want to go with a combination of two approaches. First off, you could use long polling from the client to server so that the server can notify the client as soon as a change occurs that the client is interested in.

一个新技术,很好地处理上述建议在ASP.NET是的 SignalR 。这种处理很多长轮询的详情(或何时能使用的WebSockets),所以你不必担心。

A new technology that handles the above suggestion quite nicely in ASP.NET is SignalR. This handles much of the details of long polling (or uses WebSockets when it can) so you don't have to worry about it.

其次,基于标签这个问题,它看起来像你使用SQL Server。你可以对你有兴趣有发生变化的时候,DB通知您服务表使用的数据库的通知。那么这可能会触发该服务来通知客户有关通过长期调查的连接的变化。您可以使用的SqlDependency 类做到这一点。

Secondly, based on the tags in this question it looks like you're using SQL Server. You could use database notifications on the tables you are interested in to have the DB notify your service when changes occur. This could then trigger the service to notify the client about the changes through the long poll connections. You can do this using the SqlDependency class.

我敢肯定还有其他的方法,但是这可能会相当规模以及你只能有一个服务得到通知,然后将它们分发到所有客户端。

I'm sure there are other ways, but this would probably scale quite well as you'd only have one service getting the notifications and then distributing them out to all the clients.

这篇关于良好的C#.NET解决方案来管理频繁的数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆