지난 3 일 동안이 문제로 고심하고 마침내 여기에 문제를 제기하고 있습니다.SqlDependency.OnChange가 실행되지 않는 이유는 무엇입니까?
SignalR 및 SqlDependency를 사용하여 실시간 응용 프로그램을 빌드하려고합니다. 분명히 SQLDependency가 작동하지 않습니다. 그러나, 데이터베이스 상호 작용을 필요로하지 않는 많은 기능을 시도 했으므로 SignalR이 잘 작동합니다.
아래 코드는 제 코드입니다. Here은 제가 참고하고 있습니다.
Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
NotificationHub objNotificationHub;
protected void Application_Start()
{
string connectionString = WebConfigurationManager.AppSettings["SQL"];
// SQL Command Text
string commandText = "SELECT status From tableTask";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(commandText, connection);
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
SqlDependency.Start(connectionString);
command.ExecuteReader().Dispose();
objNotificationHub = new NotificationHub();
}
}
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
objNotificationHub.SendNotifications();
}
}
}
NotificationHub.cs (SignalR 허브 클래스)
[HubMethodName("sendNotifications")]
public void SendNotifications()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.All.recieveNotification("asbc");
}
내 SqlDependency.OnChange 이벤트 즉 dependency_OnChange 데이터베이스에 발사되지 최신 정보.
나는 부여 권한이 같은 ALTER 데이타베이스보기 MyDB SET ENABLE_BROKER
및 많은 다른 사람
처럼 모든 방법을 시도했습니다. 하지만 성공하지 못했습니다.누락 된 부분이있을 수 있습니까? 또한, 내 코드가 SQL Server와 통신하는지 확인하는 방법이 있습니까?
TIA
https://msdn.microsoft.com/en-us/library/ms181122.aspx –