我有一个sqlTableDependency的问题.当我对欲望表进行插入/更新/删除时,不会调用My Changed方法. OnStatusChanged事件正常工作.
string conn = @"data source=secret server; integrated security=True; initial catalog=secret db;User id=secret user"; var mapper = new ModelToTableMapper<sqlDataModel>(); mapper.AddMapping(c => c.datavalue,"datavalue"); using (var dep = new sqlTableDependency<sqlDataModel>(conn,"data",mapper)) { dep.OnChanged += Changed; dep.OnStatusChanged += OnStatusChanged; dep.OnError += OnError; dep.TraceLevel = TraceLevel.Verbose; dep.TraceListener = new TextWriterTraceListener(Console.Out); dep.Start(); Console.WriteLine("Press a key to exit"); Console.ReadKey(); dep.Stop(); } } static void OnStatusChanged(object sender,StatusChangedEventArgs e) { Console.WriteLine(e.ToString()); } static void OnError(object sender,ErrorEventArgs e) { Console.WriteLine(e.ToString()); } static void Changed(object sender,RecordChangedEventArgs<sqlDataModel> e) { if (e.ChangeType != ChangeType.None) { var changedEntity = e.Entity; Console.WriteLine("DML operation: " + e.ChangeType); Console.WriteLine("value: " + changedEntity.datavalue); } }
以上代码我基于https://tabledependency.codeplex.com/wikipage?title=SqlTableDependency
我确信我有,我正在使用db_owner角色.我启用了代理,我看到在mssql db中创建了trigers,services等.