sqlCacheDependency section as an object ?

Last post 07-06-2009 7:51 AM by malcolms. 3 replies.

Sort Posts:

  • sqlCacheDependency section as an object ?

    07-06-2009, 3:00 AM
    • Member
      9 point Member
    • Johnny_Boy
    • Member since 10-22-2007, 8:06 PM
    • Posts 61

    Hi there,

    I wish to remove the connection strings from my web.config, and setting them programmatically. This works just fine, but there's that sqlCacheDependency (under 'caching') section which gives me a headache. It requires a connection string name within the web.config to operate.

    Moreover, I have the 'roleManager' and 'membership' elements that too need the connection string name in thier attributes.

    I've tried getting a reference to the sqlCacheDependency object in order to change it's connection string value programmatically, but couldn't.

    Can anyone think of a way this can be possible ? I've even started thinking of removing it from the web.config and create a static object for this kind of caching ..

  • Re: sqlCacheDependency section as an object ?

    07-06-2009, 7:30 AM
    • Contributor
      2,367 point Contributor
    • akhhttar
    • Member since 02-14-2007, 8:17 AM
    • Pakistan - Lahore
    • Posts 352

    Hi,

    Can you not change existing web.confi connection string programatically?

    Alternatively, Remove all configurations ( SQLCacheDependency, RolManager, Membership etc those are using connection string ) from web.config, and programatically configure them (for example in Application Start Event). Although it would not be a recommended way , but it might suits you in current situation.


    Thank You

    Muhammad Akhtar Shiekh



    Lets resolve the problem together.

    Please remember to mark the appropriate replies as answer after your question is solved, thanks

    My Blog
  • Re: sqlCacheDependency section as an object ?

    07-06-2009, 7:48 AM
    Answer
    • Contributor
      5,030 point Contributor
    • RickNZ
    • Member since 01-01-2009, 8:43 AM
    • Nelson, New Zealand
    • Posts 845

    For the SqlCacheDependcy part of your question, do this from your Global.asax:

    protected void Application_Start(object sender, EventArgs ev)
    {
        SqlDependency.Start("your conn str");
    }
    
    protected void Application_Stop(object sender, EventArgs e)
    {
         SqlDependency.Stop("your conn str");
    }
    

    SqlCacheDependency uses the same infrastructure as SqlDependency.


  • Re: sqlCacheDependency section as an object ?

    07-06-2009, 7:51 AM
    Answer
    • Star
      12,441 point Star
    • malcolms
    • Member since 06-12-2008, 12:38 AM
    • Melbourne, Australia
    • Posts 2,044

    You can remove the SQL cache dependency from your web.config.  If you do that you'll have to ensure that you don't have code that is relying on it though.

    Sincerely,
    Malcolm Sheridan

    Microsoft Certified Solution Developer
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as
    Answer" if a marked post does not actually answer your question.
Page 1 of 1 (4 items)