TableNotEnabledForNotificationException Classe

Définition

Exception levée lorsqu'une classe SqlCacheDependency est utilisée avec une table de base de données qui n'est pas activée pour les notifications de modifications.

public ref class TableNotEnabledForNotificationException sealed : SystemException
[System.Serializable]
public sealed class TableNotEnabledForNotificationException : SystemException
[<System.Serializable>]
type TableNotEnabledForNotificationException = class
    inherit SystemException
Public NotInheritable Class TableNotEnabledForNotificationException
Inherits SystemException
Héritage
TableNotEnabledForNotificationException
Attributs

Exemples

L’exemple de code suivant tente de créer un SqlCacheDependency objet et d’ajouter un élément à l’objet Cache avec une dépendance vis-à-vis de l’objet SqlCacheDependency . Si la table de base de données SQL Server n’est pas activée pour les notifications de dépendance, elle TableNotEnabledForNotificationException est levée et gérée en appelant la SqlCacheDependencyAdmin.EnableTableForNotifications méthode.

public void Page_Load(object Src, EventArgs E) 
{ 
    // Declare the SqlCacheDependency instance, SqlDep. 
    SqlCacheDependency SqlDep = null; 
    
    // Check the Cache for the SqlSource key. 
    // If it isn't there, create it with a dependency 
    // on a SQL Server table using the SqlCacheDependency class. 
    if (Cache["SqlSource"] == null) { 
        
        // Because of possible exceptions thrown when this 
        // code runs, use Try...Catch...Finally syntax. 
        try { 
            // Instantiate SqlDep using the SqlCacheDependency constructor. 
            SqlDep = new SqlCacheDependency("Northwind", "Categories"); 
        } 
        
        // Handle the DatabaseNotEnabledForNotificationException with 
        // a call to the SqlCacheDependencyAdmin.EnableNotifications method. 
        catch (DatabaseNotEnabledForNotificationException exDBDis) { 
            try { 
                SqlCacheDependencyAdmin.EnableNotifications("Northwind"); 
            } 
            
            // If the database does not have permissions set for creating tables, 
            // the UnauthorizedAccessException is thrown. Handle it by redirecting 
            // to an error page. 
            catch (UnauthorizedAccessException exPerm) { 
                Response.Redirect(".\\ErrorPage.htm"); 
            } 
        } 
        
        // Handle the TableNotEnabledForNotificationException with 
        // a call to the SqlCacheDependencyAdmin.EnableTableForNotifications method. 
        catch (TableNotEnabledForNotificationException exTabDis) { 
            try { 
                SqlCacheDependencyAdmin.EnableTableForNotifications("Northwind", "Categories"); 
            } 
            
            // If a SqlException is thrown, redirect to an error page. 
            catch (SqlException exc) { 
                Response.Redirect(".\\ErrorPage.htm"); 
            } 
        } 
        
        // If all the other code is successful, add MySource to the Cache 
        // with a dependency on SqlDep. If the Categories table changes, 
        // MySource will be removed from the Cache. Then generate a message 
        // that the data is newly created and added to the cache. 
        finally { 
            Cache.Insert("SqlSource", Source1, SqlDep); 
            CacheMsg.Text = "The data object was created explicitly."; 
            
        } 
    } 
    
    else { 
        CacheMsg.Text = "The data was retrieved from the Cache."; 
    } 
} 
Sub Page_Load(Src As Object, E As EventArgs)
   ' Declare the SqlCacheDependency instance, SqlDep.
   Dim SqlDep As SqlCacheDependency

   ' Check the Cache for the SqlSource key.
   ' If it isn't there, create it with a dependency
   ' on a SQL Server table using the SqlCacheDependency class.
   If Cache("SqlSource") Is Nothing

      ' Because of possible exceptions thrown when this
      ' code runs, use Try...Catch...Finally syntax.
      Try
         ' Instantiate SqlDep using the SqlCacheDependency constructor.
         SqlDep = New SqlCacheDependency("Northwind", "Categories")

      ' Handle the DatabaseNotEnabledForNotificationException with
      ' a call to the SqlCacheDependencyAdmin.EnableNotifications method.
      Catch exDBDis As DatabaseNotEnabledForNotificationException
         Try
            SqlCacheDependencyAdmin.EnableNotifications("Northwind")

         ' If the database does not have permissions set for creating tables,
         ' the UnauthorizedAccessException is thrown. Handle it by redirecting
         ' to an error page.
         Catch exPerm As UnauthorizedAccessException
             Response.Redirect(".\ErrorPage.htm")
         End Try

      ' Handle the TableNotEnabledForNotificationException with
            ' a call to the SqlCacheDependencyAdmin.EnableTableForNotifications method.
      Catch exTabDis As TableNotEnabledForNotificationException
         Try
            SqlCacheDependencyAdmin.EnableTableForNotifications( _
             "Northwind", "Categories")

         ' If a SqlException is thrown, redirect to an error page.
         Catch exc As SqlException
             Response.Redirect(".\ErrorPage.htm")
         End Try

      ' If all the other code is successful, add MySource to the Cache
      ' with a dependency on SqlDep. If the Categories table changes,
      ' MySource will be removed from the Cache. Then generate a message
            ' that the data is newly created and added to the cache.
      Finally
         Cache.Insert("SqlSource", Source1, SqlDep)
            CacheMsg.Text = "The data object was created explicitly."

      End Try

    Else
       CacheMsg.Text = "The data was retrieved from the Cache."
    End If
End Sub

Constructeurs

TableNotEnabledForNotificationException()

Initialise une nouvelle instance de la classe TableNotEnabledForNotificationException.

TableNotEnabledForNotificationException(String)

Initialise une nouvelle instance de la classe TableNotEnabledForNotificationException avec le message d'erreur spécifié.

TableNotEnabledForNotificationException(String, Exception)

Initialise une nouvelle instance de la classe TableNotEnabledForNotificationException avec un message d'erreur spécifié et une référence à l'exception interne ayant provoqué cette exception.

Propriétés

Data

Obtient une collection de paires clé/valeur qui fournissent des informations définies par l'utilisateur supplémentaires sur l'exception.

(Hérité de Exception)
HelpLink

Obtient ou définit un lien vers le fichier d'aide associé à cette exception.

(Hérité de Exception)
HResult

Obtient ou définit HRESULT, valeur numérique codée qui est assignée à une exception spécifique.

(Hérité de Exception)
InnerException

Obtient l'instance Exception qui a provoqué l'exception actuelle.

(Hérité de Exception)
Message

Obtient un message qui décrit l'exception active.

(Hérité de Exception)
Source

Obtient ou définit le nom de l'application ou de l'objet qui est à l'origine de l'erreur.

(Hérité de Exception)
StackTrace

Obtient une représentation sous forme de chaîne des frames immédiats sur la pile des appels.

(Hérité de Exception)
TargetSite

Obtient la méthode qui lève l'exception actuelle.

(Hérité de Exception)

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetBaseException()

En cas de substitution dans une classe dérivée, retourne la Exception qui est à l'origine d'une ou de plusieurs exceptions ultérieures.

(Hérité de Exception)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetObjectData(SerializationInfo, StreamingContext)

En cas de substitution dans une classe dérivée, définit SerializationInfo avec des informations sur l'exception.

(Hérité de Exception)
GetType()

Obtient le type au moment de l'exécution de l'instance actuelle.

(Hérité de Exception)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Crée et retourne une chaîne représentant l'exception actuelle.

(Hérité de Exception)

Événements

SerializeObjectState
Obsolète.

Se produit quand une exception est sérialisée pour créer un objet d'état d'exception qui contient des données sérialisées concernant l'exception.

(Hérité de Exception)

S’applique à