Thursday, July 12, 2012

Using SqlDependency without providing an options value Error

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

SqlDependency is awesome.  It truly is.  Problem is it has a lot of unexpected behaviors to an SqlDependency noob. 

I got this error: "When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance" couple of hours ago and I decided to share.

This error occurs if you didn't started your SqlDependency or it got closed for some reason.  I usually start it this way in the Global.asax:
    
 protected void Application_Start(Object sender, EventArgs e)
 {
   var sConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
   SqlDependency.Start(sConn);
 
   // Cache systemwide data in the application object.
   ApplicationAdapter.InitApplicationCache();
 }

You must pay attention to errors though.  Since it might fall while running, always have a check on the exception type at the Application_Error, so you'll know to restart the SqlDependency in case it stops.

Hope it helped,
Elad Shalom,
CTO at ITweetLive.com

2 comments:

  1. Hey I know this is off topic but I was wondering if you knew of any widgets I
    could add to my blog that automatically tweet my
    newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
    Also see my web site - http://cdpr.ca.gov:8765/help/urlstatusgo.html?col=dprext&url=http://www.squidoo.com/dora-the-explorer-merchandise

    ReplyDelete
  2. Even securing loan approval is simpler, with no credit report checks entirely on many small , medium sized loans,
    and with the priority focused firmly on income instead of on
    credit history payday uk
    since the pay day loan lender isn't connected with any form of credit assessment that's
    one number a borrower won't have to concern yourself with.

    ReplyDelete