如何清理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)