locked
'ds.SqlCacheDependency' threw an exception of type 'System.NotSupportedException' RRS feed

  • Question

  • User2068324065 posted

    Hi guys,

    As a follow up on my previous question: http://forums.asp.net/t/1336003.aspx 
    I would like to know if any of you have an answer to the problem with the SqlCacheDependency throwing an System.NotSupportedException when trying to update using an AccessDataSource?

    Thanks :)

    /Ole

     

    Sunday, October 26, 2008 9:20 AM

Answers

  • User-821857111 posted

    Right.  The first thing I always check with Access INSERT and UPDATE statements is to see if the parameters are added to the command obejct in the same order as they appear in the SQL.  In your case, the UpdateParameters are not.  The first one you add is @id, whereas the first one in the SQL  Update statement is @name.  Change the order that you add them to match that in the SQL and see if that fixes the problem.  With OleDb, the position of the parameters is absolutely everything.

    The second thing I recommend is to drop the use of the AccessDataSource control altogether.  It's fine for quick and dirty work, and is supposed to save you loads of coding by allowing you to work declaratively.  It was never intended to be instantiated in code-behind.  In the example above, it's not saving you any time really, and seems to be hiding errors.  I suggest you get to grips with a plain ADO.NET approach: Parameter Queries in ASP.NET with Access.  You're most of the way there anyway.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 26, 2008 4:02 PM

All replies

  • User-821857111 posted

    Since the SqlCacheDependency is not supported by Access, any attempt to make use of it through an AccessDataSource control will result in a NotSupportedException: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.accessdatasource.sqlcachedependency.aspx.  The mystery is why your code threw the exception.  There's nothing obvious there, and at a guess, I doubt you have deliberately tried to get or set the SqlCacheDependency anywhere else in code, so it has all the makings of a bug.  Something's being exposed that shouldn't be.

    Do you get this every time you try to run the page? Or just occasionally?

     

     

    Sunday, October 26, 2008 2:09 PM
  • User2068324065 posted

    I get it everytime running the page, but other places in the code, where I do something similar, it doesn't occur. I'm quite new to .net, so I haven't set SqlCacheDependency anywhere :)

     

    Sunday, October 26, 2008 2:15 PM
  • User-821857111 posted

    OK.  I figured as much :-)

    Could you post the code for the entire page that throws the error, including code-behind? And point to which line casues the error.

     

    Sunday, October 26, 2008 2:19 PM
  • User2068324065 posted

    Ok :)

     This is the Pages-class' function save

    public bool Save()
    {
      bool returnBool = false;
      AccessDataSource ds = new AccessDataSource();
      ds.DataFile =
    "~/App_Data/db.mdb";
      ds.InsertCommand =
    "INSERT INTO [pages] ([name], [text], [text_de], [text_en], [text_box], [text_box_de], [text_box_en]) VALUES (@name, @text, @text_de, @text_en, @text_box, @text_box_de, @text_box_en);";
      ds.UpdateCommand =
    "UPDATE [pages] SET [name] = @name, [text] = @text, [text_de] = @text_de, [text_en] = @text_en, [text_box] = @text_box, [text_box_de] = @text_box_de,   [text_box_en] = @text_box_en WHERE [ID] = @id";
      if (Id != null)
      {
        ds.UpdateParameters.Add(
    "id", this.id.ToString());
        ds.UpdateParameters.Add(
    "name", this.Navn);
        ds.UpdateParameters.Add(
    "text", this.Text);
        ds.UpdateParameters.Add(
    "text_de", this.Text_de);
        ds.UpdateParameters.Add(
    "text_en", this.Text_en);
        ds.UpdateParameters.Add(
    "text_box", this.Boxtext);
        ds.UpdateParameters.Add(
    "text_box_de", this.Boxtext_de);
        ds.UpdateParameters.Add(
    "text_box_en", this.Boxtext_en);
        try
        {
          ds.Update();
          returnBool =
    true;
        }   
        catch
        {
          returnBool =
    false;
        }
      }
      else
      {
        ds.InsertParameters.Add(
    "name", this.Navn);
        ds.InsertParameters.Add(
    "text", this.Text);
        ds.InsertParameters.Add(
    "text_de", this.Text_de);
        ds.InsertParameters.Add(
    "text_en", this.Text_en);
        ds.InsertParameters.Add(
    "text_box", this.Boxtext);
        ds.InsertParameters.Add(
    "text_box_de", this.Boxtext_de);
        ds.InsertParameters.Add(
    "text_box_en", this.Boxtext_en);
        try
        {
          ds.Insert();
          returnBool =
    true;
        }
        catch
        {
          returnBool =
    false;
        }
      }
      ds.Dispose();
      return returnBool;
    }

     It even returns true, but it if i look at the datasource, it contains the error and nothing is updated ?!?

    the page class looks has the following properties:

    int id
    string name
    string text
    string text_box
    string text_de
    string text_box_de
    string text_en
    string text_box_en

     

    Sunday, October 26, 2008 3:33 PM
  • User-821857111 posted

    Right.  The first thing I always check with Access INSERT and UPDATE statements is to see if the parameters are added to the command obejct in the same order as they appear in the SQL.  In your case, the UpdateParameters are not.  The first one you add is @id, whereas the first one in the SQL  Update statement is @name.  Change the order that you add them to match that in the SQL and see if that fixes the problem.  With OleDb, the position of the parameters is absolutely everything.

    The second thing I recommend is to drop the use of the AccessDataSource control altogether.  It's fine for quick and dirty work, and is supposed to save you loads of coding by allowing you to work declaratively.  It was never intended to be instantiated in code-behind.  In the example above, it's not saving you any time really, and seems to be hiding errors.  I suggest you get to grips with a plain ADO.NET approach: Parameter Queries in ASP.NET with Access.  You're most of the way there anyway.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 26, 2008 4:02 PM
  • User2068324065 posted

    Thank you very much.. the parameters in the right order-thingie worked :)

    I'll have a look at the ADO.NET approach!

    Again thank you very much for the help, it's really appreciated!!

    Sunday, October 26, 2008 4:16 PM