某些用户编辑数据时如何刷新其他用户界面上的数据 [英] How to refresh the data on other user's interface when some user edits the data

查看:49
本文介绍了某些用户编辑数据时如何刷新其他用户界面上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VB.net 应用程序中,我有一个 SQL 接口,我在 SQL 数据库中有一个 users 表供此应用程序的用户使用,当用户单击按钮更改保存在 sql 中,并为该用户刷新数据,但是我希望在某些用户单击该按钮后立即为所有用户刷新数据.

In a VB.net application I have a SQL interface, I have a users table in the SQL database for users of this application, all of them see the same data now when a user clicks a button changes are saved in the sql and data is refreshed for that user, however I want the data to be refreshed for all users as soon as some user clicks that button.

我的想法

  1. 每秒刷新数据,这不好
  2. vb.net 的 SQL 触发器,我需要更多说明!

最有效的方法是什么?

我想要一个没有计时器的解决方法!

i would like a work around without timers!

谢谢

推荐答案

SQL 提供通知订阅,这些通知提供与您的要求相关的机制.

SQL provides subscription for notifications that provide mechanisms related to your requirements.

http://msdn.microsoft.com/en-us/library/ms172483(v=sql.90).aspx

注意:已删除,因为您后来提供了使用 SQL Server 2008 R2 的信息

Note: removed since you later provided info you're using SQL Server 2008 R2

使用 System.IO.FileSystemWatcher

的老技巧

另一种方法是在您的表上创建一个 SQL 触发器,该触发器执行简单的文件时间戳更改.文件本身的大小为 0 字节,因此我们不会向其写入任何内容,从而使其成为快速操作.

Old trick with System.IO.FileSystemWatcher

The other way is to create a SQL trigger on your table that does a simple file timestamp change. File itself is 0 bytes in size so we're not writing anything to it, making it a fast operation.

然后所有客户端都会监视此文件以进行修改,当发生这种情况时,监视程序会触发更改事件,您的客户端将在该事件中重新加载其数据.

All clients then watch this file for modifications and when it happens watcher triggers a change event in which your clients would simply reload their data.

CREATE TRIGGER DataChanged
ON YourTable
FOR INSERT, UPDATE, DELETE
AS
    EXEC master..xsp_UpdateSignalFile 'YourTable.DataChanged'

这个 CLR 存储过程的想法是尽可能快地保持它的可伸缩性.在重载数据服务器的情况下,这甚至可以通过使用外部进程来更新文件来优化...

The idea of this CLR stored procedure is to be as fast as possible to keep it scalable. IN case of heavy load data server this could likely be even optimised by using external processes to update file...

您可以在 这篇 MSDN 文章 实际上与 Web 表单相关,但是除了这个 CLR 过程之外,您不需要其他东西.或许还有对整个系统如何运作的解释.

You can find the code for the CLR stored procedure in this MSDN article that is actually related to web forms, but you don't need other things than this CLR procedure. And maybe the explanation of how the whole system works.

然后,您的客户端将使用 System.IO.FileSystemWatcher 监视某个网络位置(该过程将更新文件的位置)上的文件更改,并在发生更改时更新其数据.

Your clients would then be using System.IO.FileSystemWatcher to watch for file changes on some network location (where the procedure would be updating files) and update their data when change happens.

简单而优雅的技巧,不使用轮询或对数据服务器的不必要请求.当然,您可以在多个表上设置触发器,每个表都更改不同的文件,并且根据您在客户端上显示的表单,您将在表单的整个生命周期内观察该特定文件.当用户将上下文更改为不同的数据时,您的客户端应用会释放文件观察器(并为不同的文件创建一个新的观察器).

Simple and elegant trick that doesn't use polling or unnecessary requests to the data server. You can of course have triggers on several tables each changing a different file and depending on the form you're displaying on the client you'd then watch that particular file for the lifetime of the form. When user changes context to a different data your client app releases file watcher (and creates a new one of needed for a different file).

这篇关于某些用户编辑数据时如何刷新其他用户界面上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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