c# – 未触发SqlTableDependency onchange事件

前端之家收集整理的这篇文章主要介绍了c# – 未触发SqlTableDependency onchange事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个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等.

解决方法

我在sys.transmission_queue表中找到了错误
在目标队列中排队消息时发生异常.错误

15517,State: 1. Cannot execute as the database principal because the
principal “dbo” does not exist,this type of principal cannot be
impersonated,or you do not have permission.

即使数据库已经给了我完全许可,我还没有做

ALTER AUTHORIZATION ON DATABASE::secret db TO sa
原文链接:https://www.f2er.com/csharp/100122.html

猜你在找的C#相关文章