相关疑难解决方法(0)

如何从SQL Server内存中清除SqlDependency?

如何清理SQL Server以清除过期的SqlDependency对象?从SqlDepedency对象收到事件后,我需要创建一个新事件才能获得新事件.但是,SQL Server进程的内存使用量会增加,直到超出允许的内存(SQL Server Express).如何摆脱旧查询?

码:

// Func: RegisterTableListener
using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.DatabseEventConnectionString))
{
if (cmd == null)
{
    cmd = cn.CreateCommand();

    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT HostName, LastStatus, LastDetails, xml FROM dbo.[SystemTable]";
}

lock (cmd)
{
    cmd.Connection = cn;
    cn.Open();
    cmd.Notification = null;

    //  creates a new dependency for the SqlCommand
    if (dep == null)
        dep = new SqlDependency(cmd);
    //  creates an event handler for the notification of data
    //      changes in …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server-2008 sqldependency

12
推荐指数
1
解决办法
5266
查看次数

标签 统计

c# ×1

sql ×1

sql-server-2008 ×1

sqldependency ×1