C# 在.NET应用程序中正确使用DBMS_警报
我有一个持续运行的.NET应用程序(Windows服务),它不断监听Oracle中的事件表,并在触发警报时执行一些操作。 我正在使用Oracle.ManagedDataAccess包 我正在使用DBMS_警报包来实现我的目标 执行以下代码以侦听警报:C# 在.NET应用程序中正确使用DBMS_警报,c#,.net,oracle,C#,.net,Oracle,我有一个持续运行的.NET应用程序(Windows服务),它不断监听Oracle中的事件表,并在触发警报时执行一些操作。 我正在使用Oracle.ManagedDataAccess包 我正在使用DBMS_警报包来实现我的目标 执行以下代码以侦听警报: string query = "BEGIN " + " dbms_alert.register(:Name);" + " dbms_alert.WaitOne(
string query = "BEGIN " +
" dbms_alert.register(:Name);" +
" dbms_alert.WaitOne(:Name, :Message, :Status, :timeout);" +
" dbms_alert.remove(:Name);" +
"END;";
这正是我在Oracle文档中可以找到的
解决方案可行,但我有一个小问题
当触发警报时,我的应用程序开始执行它的工作,同时我再次开始侦听(异步)。
但有时从删除警报到重新注册警报需要几秒钟的时间。在很多情况下,我都会错过警报
问题
1) 是否有一种方法可以让我在触发警报时保持监听,这样我就不会错过任何事件?
2) 从功能的角度来看,我觉得每次都必须注册并删除警报很奇怪。这真的有必要吗
是否有一种方法可以让我在发出警报时继续收听,
这样我就不会错过任何活动了
对。您在每个DB会话中注册收听一次警报,之后您将收到所有警报。无需重新注册
如果您还想接收在注册监听之前发出的警报,请检查dbms\u警报的完整规范。注册过程以了解:
procedure register(name in varchar2, cleanup in boolean default TRUE);
-- Register interest in an alert. A session may register interest in
-- an unlimited number of alerts. Alerts should be de-registered when
-- the session no longer has any interest (see 'remove'). This call
-- always performs a 'commit'.
-- Input parameters:
-- name
-- The name of the alert in which this session is interested.
-- WARNING: Alert names beginning with 'ORA$' are reserved for use for
-- products provided by Oracle Corporation. Name must be 30 bytes
-- or less. The name is case-insensitive.
-- cleanup
-- This specifies whether we should perform cleanup of any orphaned
-- pipes that may exist and are used by the dbms_alert package. This
-- cleanup is only performed on the first call to "register" for each
-- package instantiation. The default for the parameter is TRUE.
注意第二个可选参数cleanup
,默认为true
。将其作为false
传递,您的会话将不会错过注册前发出的警报
从功能的角度来看,我觉得我不得不
每次注册并删除警报。这真的有必要吗
不,没有必要
关于重新注册,请参见上文
至于删除警报。。。这是一份写得很糟糕的文件。remove
和removeall
过程不会从警报“队列”中删除警报,它们只是使您的DB会话停止侦听警报,即remove
与register
相反
是否有一种方法可以让我在发出警报时继续收听,
这样我就不会错过任何活动了
对。您在每个DB会话中注册收听一次警报,之后您将收到所有警报。无需重新注册
如果您还想接收在注册监听之前发出的警报,请检查dbms\u警报的完整规范。注册过程以了解:
procedure register(name in varchar2, cleanup in boolean default TRUE);
-- Register interest in an alert. A session may register interest in
-- an unlimited number of alerts. Alerts should be de-registered when
-- the session no longer has any interest (see 'remove'). This call
-- always performs a 'commit'.
-- Input parameters:
-- name
-- The name of the alert in which this session is interested.
-- WARNING: Alert names beginning with 'ORA$' are reserved for use for
-- products provided by Oracle Corporation. Name must be 30 bytes
-- or less. The name is case-insensitive.
-- cleanup
-- This specifies whether we should perform cleanup of any orphaned
-- pipes that may exist and are used by the dbms_alert package. This
-- cleanup is only performed on the first call to "register" for each
-- package instantiation. The default for the parameter is TRUE.
注意第二个可选参数cleanup
,默认为true
。将其作为false
传递,您的会话将不会错过注册前发出的警报
从功能的角度来看,我觉得我不得不
每次注册并删除警报。这真的有必要吗
不,没有必要
关于重新注册,请参见上文
至于删除警报。。。这是一份写得很糟糕的文件。remove
和removeall
过程不会从警报“队列”中删除警报,它们只是使您的DB会话停止侦听警报,即remove
与register
相反