// This method is called when a connection goes down or other unknown error occurs in the ProcessDispatcher. internal void InvalidateServer(string server, SqlNotification sqlNotification) { IntPtr hscp; Bid.NotificationsScopeEnter(out hscp, "<sc.SqlDependencyPerAppDomainDispatcher.Invalidate|DEP> %d#, server: '%ls'", ObjectID, server); try { List <SqlDependency> dependencies = new List <SqlDependency>(); lock (this) { // Copy inside of lock, but invalidate outside of lock. foreach (KeyValuePair <string, SqlDependency> entry in _dependencyIdToDependencyHash) { SqlDependency dependency = entry.Value; if (dependency.ContainsServer(server)) { dependencies.Add(dependency); } } foreach (SqlDependency dependency in dependencies) // Iterate over resulting list removing from our hashes. // Ensure we remove from process static app domain hash for dependency initiated invalidates. { LookupDependencyEntryWithRemove(dependency.Id); // Completely remove Dependency from commandToDependenciesHash. RemoveDependencyFromCommandToDependenciesHash(dependency); } } foreach (SqlDependency dependency in dependencies) // Iterate and invalidate. { try { dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source); } catch (Exception e) { // Since we are looping over dependencies, do not allow one Invalidate // that results in a throw prevent us from invalidating all dependencies // related to this server. if (!ADP.IsCatchableExceptionType(e)) { throw; } ADP.TraceExceptionWithoutRethrow(e); } } } finally { Bid.ScopeLeave(ref hscp); } }
// This method is called when a connection goes down or other unknown error occurs in the ProcessDispatcher. internal void InvalidateServer(string server, SqlNotification sqlNotification) { List <SqlDependency> dependencies = new List <SqlDependency>(); lock (_instanceLock) { // Copy inside of lock, but invalidate outside of lock. foreach (KeyValuePair <string, SqlDependency> entry in _dependencyIdToDependencyHash) { SqlDependency dependency = entry.Value; if (dependency.ContainsServer(server)) { dependencies.Add(dependency); } } foreach (SqlDependency dependency in dependencies) { // Iterate over resulting list removing from our hashes. // Ensure we remove from process static app domain hash for dependency initiated invalidates. LookupDependencyEntryWithRemove(dependency.Id); // Completely remove Dependency from commandToDependenciesHash. RemoveDependencyFromCommandToDependenciesHash(dependency); } } foreach (SqlDependency dependency in dependencies) { // Iterate and invalidate. try { dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source); } catch (Exception e) { // Since we are looping over dependencies, do not allow one Invalidate // that results in a throw prevent us from invalidating all dependencies // related to this server. if (!ADP.IsCatchableExceptionType(e)) { throw; } ADP.TraceExceptionWithoutRethrow(e); } } }