SqlCacheDependency 생성자

정의

SqlCacheDependency 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
SqlCacheDependency(SqlCommand)

제공된 SqlCacheDependency 클래스를 사용하여 캐시 키 종속성을 만들어 클래스의 SqlCommand 새 인스턴스를 초기화합니다.

SqlCacheDependency(String, String)

제공된 매개 변수를 사용하여 캐시 키 종속성을 만들어 클래스의 SqlCacheDependency 새 인스턴스를 초기화합니다.

SqlCacheDependency(SqlCommand)

제공된 SqlCacheDependency 클래스를 사용하여 캐시 키 종속성을 만들어 클래스의 SqlCommand 새 인스턴스를 초기화합니다.

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)

매개 변수

sqlCmd
SqlCommand

SqlCommand 개체를 만드는 데 사용되는 A SqlCacheDependency 입니다.

예외

매개 변수는 sqlCmd .입니다 null.

인스턴스의 SqlCommand 속성이 NotificationAutoEnlist 설정되어 true 있고 특성이 @ OutputCache 설정된 지시문이 SqlDependency 페이지에 있습니다 CommandNotification.

설명

이 생성자는 SQL Server 2005 제품의 쿼리 알림 기능을 사용하는 SqlCacheDependency 개체를 만드는 데 사용됩니다.

매개 변수와 sqlCmd 연결된 SQL 문에는 다음이 포함되어야 합니다.

  • 테이블 소유자의 이름을 포함하여 정규화된 테이블 이름입니다. 예를 들어 데이터베이스 소유자가 소유한 Customers라는 테이블을 참조하려면 SQL 문이 참조 dbo.customers해야 합니다.

  • Select 문의 명시적 열 이름입니다. 별표(*) 와일드카드 문자를 사용하여 테이블에서 모든 열을 선택할 수는 없습니다. 예를 들어 대신 select * from dbo.customersselect name, address, city, state from dbo.customers.

이 생성자는 페이지 수준 출력 캐싱과 함께 SQL Server 2005 쿼리 알림을 사용하여 페이지의 SqlCommand 인스턴스와 SqlCacheDependency 인스턴스를 연결하는 데 사용할 수 없습니다.

추가 정보

적용 대상

SqlCacheDependency(String, String)

제공된 매개 변수를 사용하여 캐시 키 종속성을 만들어 클래스의 SqlCacheDependency 새 인스턴스를 초기화합니다.

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)

매개 변수

databaseEntryName
String

애플리케이션의 Web.config 파일의 데이터베이스 요소에 정의된 데이터베이스의 이름입니다.

tableName
String

연결된 데이터베이스 테이블의 SqlCacheDependency 이름입니다.

예외

내부 검사에 SqlClientPermission 실패했습니다.

-또는-

databaseEntryName 테이블 기반 알림에 대해 구성된 데이터베이스 목록에서 찾을 수 없습니다.

-또는-

SqlCacheDependency 초기화하는 동안 개체가 데이터베이스에 연결할 수 없습니다.

-또는-

개체에서 SqlCacheDependency 데이터베이스 또는 개체를 지원하는 SqlCacheDependency 데이터베이스 저장 프로시저에서 사용 권한이 거부된 오류가 발생했습니다.

매개 변수는 tableName .입니다 Empty.

에 대해 SqlCacheDependency폴링을 사용할 수 없습니다.

-또는-

폴링 간격이 올바르게 구성되지 않았습니다.

-또는-

애플리케이션의 구성 파일에 연결 문자열 지정되지 않았습니다.

-또는-

애플리케이션의 구성 파일에 지정된 연결 문자열 찾을 수 없습니다.

-또는-

애플리케이션의 구성 파일에 지정된 연결 문자열 빈 문자열입니다.

매개 변수에 databaseEntryName 지정된 데이터베이스가 변경 알림에 사용할 수 없습니다.

매개 변수에 tableName 지정된 데이터베이스 테이블이 변경 알림에 사용할 수 없습니다.

databaseEntryNamenull입니다.

-또는-

tableNamenull입니다.

예제

다음 코드 예제에서는이 생성자를 사용 하 여 SqlCacheDependency 라는 데이터베이스 테이블과 연결 된 클래스의 인스턴스를 만드는 SQL Server 데이터베이스 Northwind입니다.

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

설명

이 생성자는 SQL Server 7.0 및 SQL Server 2000 제품에 대한 SqlCacheDependency 개체를 만드는 데 사용됩니다.

매개 변수에 database 전달된 데이터베이스 이름은 애플리케이션의 Web.config 파일에 정의되어야 합니다. 예를 들어 다음 Web.config 파일은 변경 알림에 대한 pubs라는 데이터베이스를 SqlCacheDependency 정의합니다.

<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>

이 생성자를 사용할 DatabaseNotEnabledForNotificationException 때 일반적으로 throw되는 두 가지 예외는 다음과 같습니다 TableNotEnabledForNotificationException. throw DatabaseNotEnabledForNotificationException 된 경우 예외 처리 코드에서 메서드를 호출 SqlCacheDependencyAdmin.EnableNotifications 하거나 명령줄 도구를 사용하여 aspnet_regsql.exe 알림에 대한 데이터베이스를 설정할 수 있습니다. throw되는 경우 메서드를 TableNotEnabledForNotificationExceptionSqlCacheDependencyAdmin.EnableTableForNotifications 호출하거나 알림을 위해 테이블을 설정하는 데 사용할 aspnet_regsql.exe 수 있습니다.

추가 정보

적용 대상