I set All right to acces the DataBase
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
but when I start SqlDependency:
bool started = SqlDependency.Start(connectionString);
//started is false and then I get this error
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code Additional information: When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance.
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;
}