When using SqlDependency without providing an options value, SqlDependency.Start() must be called pr

Posted Insus.NET

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了When using SqlDependency without providing an options value, SqlDependency.Start() must be called pr相关的知识,希望对你有一定的参考价值。

在调试SignalR程序时,提示一个异常:When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance.

解决方法是在Global.asax.cs文件中Application_Start()和Application_End()方法中添加下面高亮代码:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Insus.NET.DataBases;
using System.Data.SqlClient;

namespace Insus.NET
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            SqlDependency.Start(DB.ConnectionString);
        }

        protected void Application_End()
        {
            SqlDependency.Stop(DB.ConnectionString);
        }
    }
}
Source Code

 

以上是关于When using SqlDependency without providing an options value, SqlDependency.Start() must be called pr的主要内容,如果未能解决你的问题,请参考以下文章

When to use HTML Helper?

[NodeJS] Use Secrets When Deploying Applications with Now

Tab Key not working when using Xfce remote desktop

No module named 'winrandom' when using pycrypto

'React' must be in scope when using JSX

The problems when using a new ubuntu 18.04