【发布时间】:2017-07-10 19:02:50
【问题描述】:
我想查看 SqlDependency,但在启动时遇到问题。我正在使用下面的代码(来自https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/detecting-changes-with-sqldependency)。
在运行方法 SqlDependency.Start(connString,queue) 时抛出错误“System.Data.SqlClient.SqlException: 'Invalid object name '[core].[intServiceClient_Queue]'.'”。
我在 Sql Server 管理员帐户上连接 SSPI。我确信该对象是服务代理队列并且它存在。
void Initialization()
{
// Create a dependency connection.
SqlDependency.Start(connectionString, queueName);
}
void SomeMethod()
{
// Assume connection is an open SqlConnection.
// Create a new SqlCommand object.
using (SqlCommand command=new SqlCommand(
"SELECT ShipperID, CompanyName, Phone FROM dbo.Shippers",
connection))
{
// Create a dependency and associate it with the SqlCommand.
SqlDependency dependency=new SqlDependency(command);
// Maintain the refence in a class member.
// Subscribe to the SqlDependency event.
dependency.OnChange+=new
OnChangeEventHandler(OnDependencyChange);
// Execute the command.
using (SqlDataReader reader = command.ExecuteReader())
{
// Process the DataReader.
}
}
}
// Handler method
void OnDependencyChange(object sender,
SqlNotificationEventArgs e )
{
// Handle the event (for example, invalidate this cache entry).
}
void Termination()
{
// Release the dependency.
SqlDependency.Stop(connectionString, queueName);
}
【问题讨论】:
-
检查您的数据库以查看名为 [core].[intServiceClient_Queue] 的对象(表、存储过程、视图等)是否存在。
标签: c# sql tsql service-broker