首页 > 数据库技术 > 详细

When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance.

时间:2016-06-28 12:44:41      阅读:621      评论:0      收藏:0      [点我收藏+]

在调试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 prior to execution of a command added to the SqlDependency instance.

原文:http://www.cnblogs.com/insus/p/5622792.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!