SqlDependency一段时间后不触发

时间:2019-05-17 12:38:00

标签: c#

我创建了一个sqldependency,它仅在几分钟内就可以处理onchange事件。所有更改仅在几分钟内得到通知,并且该时间并非一直保持恒定。有时需要2分钟/ 5分钟/一些随机数。此后没有任何事件得到通知。所以问题是,可能是什么问题?还是有人早些时候遇到过同样的问题?

下面是我的代码:

private static void OnKeyClockUsersAdd(object sender, SqlNotificationEventArgs e)
        {
            SqlDependency Dependency = (SqlDependency)sender;
                        Dependency.OnChange -= OnKeyClockUsersAdd;
            CreateKeyClockUsers(ModuleSetup);
        }

public static void CreateKeyClockUsers(IModuleSetup ModuleSetup)
        {
            try
            {
                DataTable dt = new DataTable();

                SqlCommand cmd = new SqlCommand("select SettingValue from dbo.ASRSysSystemSettings where Section = 'keycloak' and SettingKey = 'startqueueforcreateuser' and SettingValue = '1'", Connection);

                cmd.CommandType = CommandType.Text;
                cmd.Notification = null;

                int EmployeeId, Id;
                string FirstName, LastName, Email, UserGroup, SelfServiceLogin, TempPassword;

                if (Connection.State == ConnectionState.Closed)
                    Connection.Open();

                SqlDependency dependency = new SqlDependency(cmd);
                dependency.OnChange += OnKeyClockUsersAdd;

                dt.Load(cmd.ExecuteReader());

                        catch (Exception e)
                        {
                            continue;
                        }
                }
            }

        }

这里sqldependency调用只有几分钟。请帮助我在哪里可以更改,以便它可以正常工作。

一段时间后超时吗?

0 个答案:

没有答案
相关问题