'ds.SqlCacheDependency' threw an exception of type 'System.NotSupportedException'

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

 

0
rocha_dk
10/26/2008 1:20:36 PM
asp.net.access-datasource 4679 articles. 0 followers. Follow

6 Replies
544 Views

Similar Articles

[PageSpeed] 28

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?

 

 


Regards Mike
[MVP - ASP/ASP.NET]
My site
0
Mikesdotnetting
10/26/2008 6:09:15 PM

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 :)

 

0
rocha_dk
10/26/2008 6:15:58 PM

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.

 


Regards Mike
[MVP - ASP/ASP.NET]
My site
0
Mikesdotnetting
10/26/2008 6:19:38 PM

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

 

0
rocha_dk
10/26/2008 7:33:31 PM

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.

 


Regards Mike
[MVP - ASP/ASP.NET]
My site
0
Mikesdotnetting
10/26/2008 8:02:00 PM

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!!

0
rocha_dk
10/26/2008 8:16:24 PM
Reply:

Web resources about - 'ds.SqlCacheDependency' threw an exception of type 'System.NotSupportedException' - asp.net.access-datasource

Resources last updated: 12/15/2015 4:13:18 AM