.NET Framework 類別庫
SqlDependency..::.Start 方法 (String, String)

更新:2007 年 11 月

啟動接聽程式,從連接字串所指定的 SQL Server 執行個體並使用指定的 SQL Server Service Broker 佇列,接收相依性變更告知。

命名空間:  System.Data.SqlClient
組件:  System.Data (在 System.Data.dll 中)

語法

Visual Basic (宣告)
<HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading := True)> _
Public Shared Function Start ( _
    connectionString As String, _
    queue As String _
) As Boolean
Visual Basic (使用方式)
Dim connectionString As String
Dim queue As String
Dim returnValue As Boolean

returnValue = SqlDependency.Start(connectionString, _
    queue)
C#
[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)]
public static bool Start(
    string connectionString,
    string queue
)
Visual C++
[HostProtectionAttribute(SecurityAction::LinkDemand, ExternalThreading = true)]
public:
static bool Start(
    String^ connectionString, 
    String^ queue
)
J#
/** @attribute HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true) */
public static boolean Start(
    String connectionString,
    String queue
)
JScript
public static function Start(
    connectionString : String, 
    queue : String
) : boolean

參數

connectionString
型別:System..::.String

連接字串,其指定從中取得變更告知的 SQL Server 執行個體。

queue
型別:System..::.String

所要使用的現有 SQL Server Service Broker 佇列。若是 null,則會使用預設佇列。

傳回值

型別:System..::.Boolean

如果接聽程式成功初始化,則為 true,如果相容的接聽程式已存在,則為 false

例外狀況

例外狀況條件
ArgumentNullException

connectionString 參數為 NULL。

InvalidOperationException

connectionString 參數和這個方法的前一個呼叫相同,但參數不同。

方法從 SQLCLR 中呼叫。

SecurityException

呼叫端沒有必要的 SqlClientPermission 程式碼存取安全性 (CAS) 使用權限。

SqlException

後續的方法呼叫使用對等 connectionString 參數,但使用者不同或使用者未預設為相同結構描述。

此外,也會發生任何基礎 SqlClient 例外狀況。

備註

注意事項:

套用至這個型別或成員的 HostProtectionAttribute 屬性 (Attribute) 具有下列 Resources 屬性 (Property) 值:ExternalThreadingHostProtectionAttribute 不會影響桌面應用程式 (這些應用的啟動方式一般都是按兩下圖示、輸入命令或在瀏覽器輸入 URL)。如需詳細資訊,請參閱 HostProtectionAttribute 類別或 SQL Server 程式設計和主機保護屬性

這個方法會啟動 AppDomain 的接聽程式,從 connectionString 參數所指定的 SQL Server 執行個體接收相依性告知。可以使用不同連接字串,為多個伺服器呼叫這個方法一次以上。

如果未指定佇列名稱,SqlDependency 會在伺服器上建立用於整個程序的暫存佇列和服務,即使該程序涉及一個以上的 AppDomain。此佇列和服務在應用程式關閉時會被自動移除。

在下列限制下,可執行對 Start 方法的多個呼叫:

  • 具相同參數 (在呼叫執行緒中有相同連接字串、佇列和 Windows 認證) 的多個呼叫為有效。

  • 具不同連接字串的多個呼叫為有效,條件是:

    • 每個連接字串各指定不同的資料庫,或

    • 每個連接字串各指定不同的使用者,或

    • 呼叫來自不同的應用程式定義域。

平台

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.5、3.0、2.0
請參閱

參考

其他資源

標記 :


Page view tracker