Start Method

SqlDependency.Start Method

 

Starts the listener for receiving dependency change notifications.

Namespace:   System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticStart(String)

Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string.

System_CAPS_pubmethodSystem_CAPS_staticStart(String, String)

Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string using the specified SQL Server Service Broker queue.

The SqlDependency listener will restart when an error occurs in the SQL Server connection.

Multiple calls to the Start method can be made, subject to the following restrictions:

  • Multiple calls with identical parameters (the same connection string and Windows credentials in the calling thread) are valid.

  • Multiple calls with different connection strings are valid as long as:

    • Each connection string specifies a different database, or

    • Each connection string specifies a different user, or

    • The calls come from different application domains.

You can make the SqlDependency work correctly for applications that use multiple threads to represent different user credentials without giving the dbo role to the group, because different user can subscribe and listen (using System.Web.Caching.SqlCacheDependency or SqlCommand) to a notification queue created by an administrator. When the relevant application domain starts, call Start with the (Windows) credentials of a user that has permission to initialize a service/queue (the CREATE QUEUE and CREATE SERVICE permissions for the database). Ensure that Start is only called once per AppDomain, otherwise an ambiguity exception is raised. The user thread must have permission to subscribe to the notification (the SUBSCRIBE QUERY NOTIFICATIONS permission for the database). SqlDependency will associate the subscription request of a non-administrator user to the service/queue created by the administrator.

Return to top
Show:
© 2016 Microsoft