如何从SQL Server内存中清除SqlDependency?
如何清理SQL Server以清除过期的SqlDependency
对象?从SqlDepedency
对象收到事件后,我需要创建一个新事件才能获得新事件。但是,SQL Server进程的内存使用量会增加,直到超出允许的内存(SQL Server Express)。如何摆脱旧查询?
码:
// Func: RegisterTableListenerusing (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 the database. dep.OnChange += new OnChangeEventHandler(dependency_OnChange); using (SqlDataReader reader = cmd.ExecuteReader()) { // code here to read }}}// Func dependency_OnChange//SqlDependency dep = sender as SqlDependency;dep.OnChange -= dependency_OnChange;RegisterTableListener();
qq_遁去的一_1
相关分类