我想檢查出SqlDependency但開始時遇到問題。我正在使用下面的代碼(這是從https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/detecting-changes-with-sqldependency)。C#SqlDependency - 無效的對象名
錯誤「System.Data.SqlClient.SqlException:'運行方法SqlDependency.Start(connString,queue)時引發'無效對象名'[core]。[intServiceClient_Queue]'。'」。
我在Sql Server Admin帳戶上連接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]存在。 –