我设置了访问数据库的权限
use DbName
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO dbuser
use DbName
GRANT SELECT ON OBJECT::schema.tableName TO dbuser
Use DbName
GRANT RECEIVE ON QueryNotificationErrorsQueue TO dbuser
ALTER DATABASE DbName SET TRUSTWORTHY ON
use DbName
alter database DbName SET ENABLE_BROKER
但当我开始SQL依赖关系:
bool started = SqlDependency.Start(connectionString);
//started 是 false 然后我得到这个错误
System.Data.dll 中发生“System.InvalidOperationException”类型的异常,但未在用户代码中处理
附加信息:当使用 SqlDependency 而不提供选项值时,必须在执行添加到 SqlDependency 实例的命令之前调用 SqlDependency.Start()。
C# code:
private static bool notificationEnabled = false;
private string connString= "Data Source=(local);Initial Catalog=MyDB;UID=dbuser; PWD=pass;";
public static void EnableNotifications()
{
// prevent for calling twice
if (notificationEnabled)return;
System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications(connString);
//startResult is false always
bool startResult = SqlDependency.Start(connString);
notificationEnabled = true;
}
尝试将队列名称添加到您的开始:
bool startResult = SqlDependency.Start(connString, queueName)
我还必须将服务名称和超时添加到我的 SqlDependency 构造函数中才能正常工作。 (虽然是 VB 语言,但你明白了)
dependency = New SqlDependency(command, "Service=" + SERVICE_NAME + ";", Int32.MaxValue)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)