SqlDependency 失败,因为无法通知或提供的 SELECT 语句

SqlDependency failed because A SELECT statement that cannot be notified or was provided

我正在尝试使用 SqlDependency,并且我阅读了 Microsoft 的文章 Creating a Query for Notification, Query Notification Permissions。我仔细检查了很多次,似乎都符合文章中提到的需要这是我的代码。

private void InitialSqlDependency()
    {
        using (var connection = new SqlConnection(_connString))
        {
            connection.Open();
            string message = string.Empty;

            string query = @"SELECT ModifiedOn FROM [dbo].[ContainerTransactions]";

            using (var command = new SqlCommand(query, connection))
            {
                command.Notification = null;

                SqlDependency dependency = new SqlDependency(command);
                dependency.OnChange += new OnChangeEventHandler(Dependency_OnChange);

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

                SqlDataReader dr = command.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    message = dr[0].ToString();
                }
            }
        }
    }

    private void Dependency_OnChange(object sender, SqlNotificationEventArgs e)
    {
        _logger.Debug("ContainerWatch Dependency Fired!");

        if (e.Type == SqlNotificationType.Change)
        {
            _logger.Debug("ContainerWatch Change Fired!");

            this.InitialSqlDependency();
        }
    }

但是,总是订阅失败。我看到 SqlNotificationInfo returns Query which means A SELECT statement that cannot be notified or was provided. Here is my debug img

SELECT语句非常简单,请问有什么可能导致失败的原因吗?

我找到了根本原因,因为The statement must not reference tables with computed columns。我使用下面的查询来查看计算列

SELECT * FROM sys.computed_columns WHERE object_id = OBJECT_ID('ContainerTransactions')

因此,我认为我不能在此 table.

上使用 SqlDependency