C#OracleDependency:事件未触发

时间:2018-10-23 08:23:24

标签: c# .net oracle

亲爱的

我正在尝试使用OracleDependecy通知更新。

在系统表USER_CHANGE_NOTIFICATION_REGS内,我可以看到已注册的操作(带有我的IpAddress和端口)

我正在控制台应用程序项目(.Net标准)中使用Nuget软件包 Oracle.ManagedDataAccess (v.4.122.18.3)

我的Oracle版本是这样的: Oracle Database 11g企业版11.2.0.3.0版-64位生产 PL / SQL版本11.2.0.3.0-生产

但是,这不起作用,更新完成后,不会触发事件 dependency_OnChange 。 有人知道为什么吗? 在哪里可以找到可行的项目示例?

预先感谢

在下面,您可以找到代码:

using (OracleConnection oraConnection = new OracleConnection(oraConnectionString))
        {
            try
            {
                // Open the connection
                oraConnection.Open();

                // Create the Select command retrieving single row from table. 
                OracleCommand selectCommand = new OracleCommand(oraQuery, oraConnection);

                // Create an OracleDependency object and set it to track the result set returned by selectCommand. 
                oraDependency = new OracleDependency(selectCommand);

                //Port
                OracleDependency.Port = 3048;

                // Setting object-based change notification registration 
                oraDependency.QueryBasedNotification = false;

                // When the IsNotifiedOnce property is true, only the first change  
                // of the traced result set will generate a notification. 
                // Otherwise, notifications will be sent on each change  
                // during the selectCommand.Notification.Timeout period. 
                selectCommand.Notification.IsNotifiedOnce = false;

                // Set the event handler to the OnChange event. 
                oraDependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                // When the select command is executed at the first time, a notification  
                // on changes of the corresponding result set is registered on the server.
                //selectCommand.CommandTimeout = 5;
                OracleDataReader reader = selectCommand.ExecuteReader(CommandBehavior.Default);

                // Pause the current thread to process the event. 
                Console.WriteLine("Ok");
                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception encountered: {0}", e.Message);
            }
            // Always try to both remove the notification registration
            // oraConnection.Close() is autimatically called by .Dispose at the end of our 'using' statement
            finally
            {
                try
                {
                    oraDependency.RemoveRegistration(oraConnection);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception encountered: {0}", e.Message);
                }
            }
        }

0 个答案:

没有答案