Editar

Compartir a través de


SqlDependency.Start Method

Definition

Starts the listener for receiving dependency change notifications.

Overloads

Start(String)

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

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.

Remarks

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 users can subscribe and listen (using 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.

Start(String)

Source:
System.Data.SqlClient.notsupported.cs

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

public:
 static bool Start(System::String ^ connectionString);
public static bool Start (string connectionString);
static member Start : string -> bool
Public Shared Function Start (connectionString As String) As Boolean

Parameters

connectionString
String

The connection string for the instance of SQL Server from which to obtain change notifications.

Returns

true if the listener initialized successfully; false if a compatible listener already exists.

Exceptions

The connectionString parameter is NULL.

The connectionString parameter is the same as a previous call to this method, but the parameters are different.

The method was called from within the CLR.

The caller does not have the required SqlClientPermission code access security (CAS) permission.

A subsequent call to the method has been made with an equivalent connectionString parameter with a different user, or a user that does not default to the same schema.

Also, any underlying SqlClient exceptions.

Remarks

This method starts the listener for the AppDomain for receiving dependency notifications from the instance of SQL Server specified by the connectionString parameter. This method may be called more than once with different connection strings for multiple servers.

For additional remarks, see Start.

See also

Applies to

Start(String, String)

Source:
System.Data.SqlClient.notsupported.cs

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.

public:
 static bool Start(System::String ^ connectionString, System::String ^ queue);
public static bool Start (string connectionString, string queue);
static member Start : string * string -> bool
Public Shared Function Start (connectionString As String, queue As String) As Boolean

Parameters

connectionString
String

The connection string for the instance of SQL Server from which to obtain change notifications.

queue
String

An existing SQL Server Service Broker queue to be used. If null, the default queue is used.

Returns

true if the listener initialized successfully; false if a compatible listener already exists.

Exceptions

The connectionString parameter is NULL.

The connectionString parameter is the same as a previous call to this method, but the parameters are different.

The method was called from within the CLR.

The caller does not have the required SqlClientPermission code access security (CAS) permission.

A subsequent call to the method has been made with an equivalent connectionString parameter but a different user, or a user that does not default to the same schema.

Also, any underlying SqlClient exceptions.

Remarks

This method starts the listener for the AppDomain for receiving dependency notifications from the instance of SQL Server specified by the connectionString parameter. This method may be called more than once with different connection strings for multiple servers.

If no queue name is specified, SqlDependency creates a temporary queue and service in the server that is used for the entire process, even if the process involves more than one AppDomain. The queue and service are automatically removed upon application shutdown.

For additional remarks, see Start.

See also

Applies to