4

i like to know how anyone can work SqlDependency in web project. i got one code from stackoverflow like Asp.Net Signal R - Detect Changes in Database ? Asp.net Web Forms

//Set up dependency
protected void Application_Start()
{
        //...
   SqlDependency.Start(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); 
}


protected void Application_End()
{
    SqlDependency.Stop(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); 
}

SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

i guess the sql dependency onchange method should be in any event in global.asax file....am i right. but see the code they just simply instantiate SqlDependency out of any event. so i like to know does the above code works at all? if yes then please explain when actually SqlDependency instance will be created if we just put these two line

SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

inside global.asax file.

if we need to work with sql dependency class then we need to enable broker at database level. so i like to know when our database is hosted in shared environment then can we enable broker. suppose i have hosted my db in ORCSWEB shared location where many other database also exist then ORCSWEB will at all allow me to enable broker for my db?

another important point

To subscribe query notification, we need to give permission to IIS service account GRANT SUBSCRIBE QUERY NOTIFICATIONS TO “Domain\ASPNET”

how to give SUBSCRIBE QUERY NOTIFICATIONS rights to IIS ? i need to know the full steps.

thanks

Community
  • 1
  • 1
Thomas
  • 33,544
  • 126
  • 357
  • 626

1 Answers1

-1

Here is an example on SQLDependency I don't believe you could use it in Global.asax as it works per SQL Command like in this Example Also SQL command cannot be Select *, INSERT or UPDATE so you would need some mechanism to check for that or try catch block, and logic to handle that.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265