1
我已經設置了應該知道,以改變它的數據源,如下,更多或更少的清單:爲什麼SQL Server Service Broker沒有通知我插入到表中?
public class SharedList<T>: ObservableCollection<T> where T: XTimeEntity
{
private const string DependencyQuery = "select TITLE_ACTIVE, TITLE_NAME from TITLE";
private readonly SqlDependency _dependency = new SqlDependency();
public SharedList()
{
var connectionString = ConfigurationManager.ConnectionStrings["XTime900Context"].ConnectionString;
SqlDependency.Stop(connectionString);
using (var sqn = new SqlConnection(connectionString))
{
using (var cmd = new SqlCommand(DependencyQuery, sqn))
{
_dependency.AddCommandDependency(cmd);
}
}
_dependency.OnChange += DependencyOnOnChange;
PopulateList();
SqlDependency.Start(connectionString);
}
}
然而,當我在執行SSMS insert TITLE values (1, 1, 'Mr.')
,沒有觸發的事件。觸發事件的更改是否必須在SqlConnection對象上進行?
首先你需要模式名稱。選擇..從Schema.TableName。 –
是的,@Janis,我已經添加,並且正在接收通知,但一切都不好:[我有另一個問題] [1]:http://stackoverflow.com/questions/20234287/why-am- i-getting-an-open-data-reader-exception-with-my-sqldependency-subscript – ProfK