Start Method
Collapse the table of content
Expand the table of content

SqlDependency.Start Method

Starts the listener for receiving dependency change notifications.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  NameDescription
Public method Static member Start(String) Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string.
Public method Static member Start(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.
Top

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 group the role of dbo. A user with database administrator privileges must call Start. A different user can subscribe and listen (using [System.Web.Caching.SqlCacheDependency] or SqlCommand) to the notification queue created by administrator, as follows:  Call Start only once for the specified server/database pair (otherwise, an ambiguity exception will be raised). When the relevant application domain starts, make sure Start is called for that AppDomain and it is called with (Windows) credentials of user that has rights to initialize service/queue.  Then, the user thread must have permission to subscribe for the notification. SqlDependency will associate the subscription request of a non-administrator user to the service/queue created by the administrator.

Community Additions

ADD
Show:
© 2016 Microsoft