I have show notification or alert on asp.net page based on database server data insertion, so I want to know if it is possible to do this task by push models?
1 Answer
You can use SignalR to send notifications from your web server to your clients: http://signalr.net/.
To send notifications from SQL Server to your web server, you can use the SqlDependency
and SqlCacheDependency
classes.
From the guidelines, http://msdn.microsoft.com/en-US/library/9dz445ks(v=vs.110).aspx,
SqlDependency.Start(myConnectionString);
using (SqlConnection connection = new SqlConnection(myConnectionString))
{
using (SqlCommand command = new SqlCommand("SELECT ... FROM MyTable", connection))
{
SqlCacheDependency dependency = new SqlCacheDependency(command);
// Refresh the cache after the number of minutes
// listed below if a change does not occur.
// This value could be stored in a configuration file.
int numberOfMinutes = 3;
DateTime expires = DateTime.Now.AddMinutes(numberOfMinutes);
Response.Cache.SetExpires(expires);
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
Response.AddCacheDependency(dependency);
connection.Open();
}
}