Share via


SqlCacheDependency Oluşturucular

Tanım

SqlCacheDependency sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

SqlCacheDependency(SqlCommand)

Önbellek anahtarı bağımlılığı oluşturmak için sağlanan SqlCommand öğesini kullanarak sınıfının yeni bir örneğini SqlCacheDependency başlatır.

SqlCacheDependency(String, String)

Önbellek anahtarı bağımlılığı oluşturmak için sağlanan parametreleri kullanarak sınıfının yeni bir örneğini SqlCacheDependency başlatır.

SqlCacheDependency(SqlCommand)

Önbellek anahtarı bağımlılığı oluşturmak için sağlanan SqlCommand öğesini kullanarak sınıfının yeni bir örneğini SqlCacheDependency başlatır.

public:
 SqlCacheDependency(System::Data::SqlClient::SqlCommand ^ sqlCmd);
public SqlCacheDependency (System.Data.SqlClient.SqlCommand sqlCmd);
new System.Web.Caching.SqlCacheDependency : System.Data.SqlClient.SqlCommand -> System.Web.Caching.SqlCacheDependency
Public Sub New (sqlCmd As SqlCommand)

Parametreler

sqlCmd
SqlCommand

SqlCommand Nesne oluşturmak için kullanılan.SqlCacheDependency

Özel durumlar

sqlCmd parametresidirnull.

Örneğin SqlCommandNotificationAutoEnlist özelliği olarak true ayarlanmıştır ve sayfada özniteliği olarak SqlDependency ayarlanmış CommandNotificationbir @ OutputCache yönerge vardır.

Açıklamalar

Bu oluşturucu, SQL Server 2005 ürünlerinin sorgu bildirimi özelliğini kullanan nesneler oluşturmak SqlCacheDependency için kullanılır.

parametresiyle sqlCmd ilişkili SQL deyimleri aşağıdakileri içermelidir:

  • Tablo sahibinin adı da dahil olmak üzere tam tablo adları. Örneğin, veritabanı sahibine ait Müşteriler adlı tabloya başvurmak için SQL deyiminin öğesine dbo.customersbaşvurması gerekir.

  • Select deyimindeki açık sütun adları. Tablodan tüm sütunları seçmek için yıldız (*) joker karakterini kullanamazsınız. Örneğin, yerine select * from dbo.customerskullanmanız select name, address, city, state from dbo.customersgerekir.

Bu oluşturucu, SQL Server 2005 sorgu bildirimlerini sayfa düzeyinde çıktı önbelleğe alma ile kullanarak bir örneği sayfadaki bir SqlCacheDependency örnekle ilişkilendirmek SqlCommand için kullanılamaz.

Ayrıca bkz.

Şunlara uygulanır

SqlCacheDependency(String, String)

Önbellek anahtarı bağımlılığı oluşturmak için sağlanan parametreleri kullanarak sınıfının yeni bir örneğini SqlCacheDependency başlatır.

public:
 SqlCacheDependency(System::String ^ databaseEntryName, System::String ^ tableName);
public SqlCacheDependency (string databaseEntryName, string tableName);
new System.Web.Caching.SqlCacheDependency : string * string -> System.Web.Caching.SqlCacheDependency
Public Sub New (databaseEntryName As String, tableName As String)

Parametreler

databaseEntryName
String

Uygulamanın Web.config dosyasının databases öğesinde tanımlanan veritabanının adı.

tableName
String

ile ilişkilendirilmiş veritabanı tablosunun SqlCacheDependency adı.

Özel durumlar

İç denetim SqlClientPermission başarısız oldu.

-veya-

, databaseEntryName tablo tabanlı bildirimler için yapılandırılmış veritabanları listesinde bulunamadı.

-veya-

Nesne SqlCacheDependency başlatma sırasında veritabanına bağlanamadı.

-veya-

Nesne, SqlCacheDependency veritabanında veya nesneyi destekleyen veritabanı saklı yordamlarında izin reddedildi hatasıyla SqlCacheDependency karşılaştı.

tableName parametresidirEmpty.

Yoklama için etkinleştirilmedi SqlCacheDependency.

-veya-

Yoklama aralığı doğru yapılandırılmamış.

-veya-

Uygulamanın yapılandırma dosyasında bağlantı dizesi belirtilmedi.

-veya-

Uygulamanın yapılandırma dosyasında belirtilen bağlantı dizesi bulunamadı.

-veya-

Uygulamanın yapılandırma dosyasında belirtilen bağlantı dizesi boş bir dizedir.

parametresinde databaseEntryName belirtilen veritabanı değişiklik bildirimleri için etkinleştirilmedi.

parametresinde tableName belirtilen veritabanı tablosu değişiklik bildirimleri için etkinleştirilmedi.

databaseEntryName, null değeridir.

-veya-

tableName, null değeridir.

Örnekler

Aşağıdaki kod örneği, Northwind adlı bir SQL Server veritabanında Kategoriler adlı veritabanı tablosuyla ilişkili sınıfın bir örneğini SqlCacheDependency oluşturmak için bu oluşturucuyu kullanır.

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

Açıklamalar

Bu oluşturucu, SQL Server 7.0 ve SQL Server 2000 ürünleri için nesneler oluşturmak SqlCacheDependency için kullanılır.

parametresine database geçirilen veritabanı adı, uygulamanın Web.config dosyasında tanımlanmalıdır. Örneğin, aşağıdaki Web.config dosyası değişiklik bildirimleri için SqlCacheDependency pubs adlı bir veritabanı tanımlar.

<configuration>
  <connectionStrings>
    <add name="Pubs" connectionString="Data Source=(local); Initial Catalog=pubs; Integrated Security=true"; providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <caching>
      <sqlCacheDependency enabled = "true" pollTime = "60000" >
        <databases>
          <add name="pubs"
            connectionStringName="pubs"
            pollTime="9000000"
            />
        </databases>
      </sqlCacheDependency>
    </caching>
  </system.web>
</configuration>

Bu oluşturucu kullanıldığında genellikle iki özel durum oluşturulur: DatabaseNotEnabledForNotificationException ve TableNotEnabledForNotificationException. oluşturulursa DatabaseNotEnabledForNotificationException , yöntemini özel durum işleme kodunda çağırabilir SqlCacheDependencyAdmin.EnableNotifications veya komut satırı aracını kullanarak veritabanını bildirimler için ayarlayabilirsiniz aspnet_regsql.exe . oluşturulursa TableNotEnabledForNotificationException yöntemini çağırabilir SqlCacheDependencyAdmin.EnableTableForNotifications veya tabloyu bildirimler için ayarlamak için kullanabilirsiniz aspnet_regsql.exe .

Ayrıca bkz.

Şunlara uygulanır