简体   繁体   English

如何从SQL Server发出c#控制台应用程序的信号?

[英]How can I signal a c# console app from SQL Server?

Rather than poll against some tables, I'd like to signal a waiting c# app that there are new rows to be processed in a table, maybe via a trigger. 我不想对某些表进行轮询,而是想发出一个等待的c#应用程序,表示要在表中处理新行,可能是通过触发器。 Is there some way for the database to signal to a console app, or am I stuck polling the table looking for new rows? 有没有办法让数据库向控制台应用程序发出信号,或者我是否卡在表中查找新行?

Take a look at Query Notifications (SQL Server 2005+). 查看查询通知 (SQL Server 2005+)。

Microsoft SQL Server 2005 introduces query notifications, new functionality that allows an application to request a notification from SQL Server when the results of a query change. Microsoft SQL Server 2005引入了查询通知,这是一种新功能,允许应用程序在查询结果发生更改时从SQL Server请求通知。 Query notifications allow programmers to design applications that query the database only when there is a change to information that the application has previously retrieved. 查询通知允许程序员设计仅在应用程序先前检索到的信息发生更改时才查询数据库的应用程序。

There is an example here of how to write a simple form app to register a query for notification: http://msdn.microsoft.com/en-us/library/a52dhwx7(VS.80).aspx . 这里有一个例子,说明如何编写一个简单的表单应用程序来注册通知查询: http//msdn.microsoft.com/en-us/library/a52dhwx7(VS.80).aspx

This does require the Service Broker to be enabled on the database. 这确实需要在数据库上启用Service Broker

You should take a look at the notes in the Remarks section of the MSDN SqlDependency documentation to make sure it is the right choice for your scenario 你应该看看在的备注部分的注释 MSDN的SqlDependency文档 ,以确保它是为您的方案是正确的选择

Check if SqlCacheDependency can be of any use... 检查SqlCacheDependency是否可以使用...

http://www.asp.net/data-access/tutorials/using-sql-cache-dependencies-cs http://www.asp.net/data-access/tutorials/using-sql-cache-dependencies-cs

如果是SQL Server 2008,您也可以使用Service Broker使用基于事件的激活

I have used WCF with SQLCLR to get data from another process into SQL, worked pretty good apart from some minor quirks to set it up. 我已经使用WCF和SQLCLR将来自另一个进程的数据导入SQL,除了一些小问题之外,它还能很好地设置它。 So you can just call other processes from SQl this way. 因此,您可以通过这种方式从SQl调用其他进程。 It's usually quite hard to deploy to customers though, DBA don't like this sort of stuff. 这通常很难部署到客户,但DBA不喜欢这种东西。

GJ GJ

Check out SQL Service Broker . 查看SQL Service Broker Using a Queue and the WAITFOR syntax I have changed a custom polling service into a blocking/signal service. 使用Queue和WAITFOR语法我已将自定义轮询服务更改为阻塞/信号服务。 You could also look at the event-activation . 您还可以查看事件激活 Either way this would allow for a transactional way to call your external program in a non-polling async way that will not slow down triggers and database locks. 无论哪种方式,这将允许以非轮询异步方式调用外部程序的事务方式,这不会减慢触发器和数据库锁。

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

相关问题 我可以使用 SQL 触发器来跟踪数据库上 C# 控制台应用程序的更改吗? - Can I use SQL Triggers to track changes from C# Console App on Database? 如何使用 C# 从 SQL 服务器检索点? - How can I retrieve a Point from SQL Server with C#? 如何评估 c# 控制台应用程序中的 Excel 功能? - How can I evaluate Excel functions in c# Console App? 如何在 C# 控制台应用程序中使用音效? - How can I use sound effect in C# console app? 如何从 C# 控制台应用程序中的事件网格(Azure 门户)的 QueueStorage 接收消息? - How can I receive the message from a QueueStorage of Event Grid (Azure Portal) in a C# Console app? 如何在C#控制台应用程序的行首处允许用户输入? - How can I allow user input from the beginning of the line in C# console app? 在 C# 控制台应用程序中显示 SQL Server 表内容 - Show SQL Server table content in C# console app 如何在另一台计算机上运行包含本地SQL Server数据库的C#app? - How can I run C# app which contains local SQL Server database on another computer? 如何在客户端计算机上安装 C# 桌面应用程序和 SQL 服务器数据库而不安装 SQL 服务器 - How can I Install C# desktop app with SQL Server database on client machine without installing SQL Server 如何在 C# 控制台应用程序搜索功能中搜索 SQL Server 表? - How to search SQL Server table in C# Console app search function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM