locked
DataServiceQueryException when accessing Table storage via linq RRS feed

  • Question

  • hi together,

    i try to access my table storage via following linq statement:

    var results = from b in this.context.Books
                              where b.UserID.Equals(uid)
                              select b;
    
    List<Book> myBookList = results.ToList<Book>();


    if i do the results.ToList<Book>(); command i got the DataServiceQueryException an error occured while processing this request. in this special case, the table i access is empty, but earlier (july sdk) that was no problem.

    Detail information about the exception:

    System.Data.Services.Client.DataServiceClientException: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
     <code>InvalidInput</code>
     <message xml:lang="de-AT">One of the request inputs is not valid.</message>
    </error>


    thx for your help
    greatz
    flo
    Yes, i'm living in the cloud
    Thursday, December 3, 2009 5:48 PM

Answers

  • thanks for your effort allen.
    i did a workaround in my case (got the exception when the table i want to query is empty) with a try-catch block and catched the specific exception which will be thrown if the table is empty...

    but if anybody detects the source of the error, please let me know how i can solve the problem in a better way

    greatz
    flo
    Yes, i'm living in the cloud
    Wednesday, December 9, 2009 3:18 PM

All replies

  • is the "UserID" attribute is used as a row key or partition key?, if so make sure that the "uid" variable doesn't contain any disallowed characters, check this post for more info http://mosalem.blogspot.com/2009/12/windows-azure-tables.html

    Best Regards,
    Mohamed Mosallem
    www.mosallem.com

    Thursday, December 3, 2009 7:49 PM
  • no it is neither row or partition key, it contains normal string value. is it necessary that the attribute is row or partition key, i do not think so...
    could it be a problem if the query results in an empty result set?

    greatz
    flo

    Yes, i'm living in the cloud
    Thursday, December 3, 2009 7:53 PM
  • in my case the table was empty and i tried to query the rowkey column for value X where X contained special character and i received this error
    can you try to insert some values to the table and see what will happen

    Best Regards,
    Mohamed Mosallem
    www.mosallem.com
    Thursday, December 3, 2009 7:57 PM
  • if i try to save a book i get the same error!

    save:
    AddObject("Books", myBook);
    SaveChanges();

    call of save changes causes the exception...

    greatz

    Yes, i'm living in the cloud
    Thursday, December 3, 2009 8:11 PM
  • can you describe your table (columns, data types, the partition key and the row key)  and the values u try to insert?

    Best Regards,
    Mohamed Mosallem
    www.mosallem.com

    Thursday, December 3, 2009 8:15 PM
  • the table has 8 columns.
    row key= Title of a book
    partition key = author of a book

    the other columns are strings and one double value.

    i has written three classes for the access on the tablestorage system. One of them is this BookEntryDataSource class like described in the November Training Kit.
    The only difference from my app to the one in the training kit is, that i do not use such a asp:ObjectDataSource instance... could that be a problem? otherwise, i had a second DataSource class for a second table and there it works fine without the asp:ObjectDataSource...

    greatz

    Yes, i'm living in the cloud
    Thursday, December 3, 2009 8:20 PM
  • i don't think it's related to the objectdatasource, what values were in the book u tried to save??
    Thursday, December 3, 2009 8:25 PM
  • Constructor:
    public Book(string uid, string title, string author, double price, string fncover, string fnbook, string coveruri, string pdfuri)

    i tried to save:
    new Book("test1", "test", "something", 12.0, "", "", "", "");

    the empty strings should not be the problem...
    Yes, i'm living in the cloud
    Thursday, December 3, 2009 8:29 PM
  • Hi,

    Could you please post a simple demo project that can reproduce this issue for me to test? You can upload the project to http://skydrive.live.com/ and paste download link here.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, December 4, 2009 8:08 AM
  • http://cid-75f239bf096830c7.skydrive.live.com/browse.aspx/.Public?uc=1

    my testproject, same error as described above occurs.

    greatz
    flo
    Yes, i'm living in the cloud
    Friday, December 4, 2009 9:26 AM
  • i found the problem.
    if the linq query does not find any entry with the given userID the access with restuls.ToList() results with the DataServiceQueryException.

    any solutions? (i recur, but this worked fine with sdk july...)

    edit: could it be that the table for the entities, i want to save in, was not created until i add a book?

    greatz
    flo
    Yes, i'm living in the cloud
    Friday, December 4, 2009 10:14 AM
  • Hi,

    I'm unable to reproduce this exception with your code. Could you check whether "TestData" table exists in database? Or you can add following code to add the Table first.

     protected void Page_Load(object sender, EventArgs e)
            {
                TestEntryDataSource teds = new TestEntryDataSource();
                var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
                var tbc= account.CreateCloudTableClient();
                tbc.CreateTableIfNotExist("TestData");

                teds.AddNewBook(new TestData("test1", "somethingTitle", "somethingAuthor", 12.0, "", "", "", ""));
            
                List<TestData> tmp = teds.GetBooksByUserID("test1");
            }
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, December 4, 2009 11:09 AM
  • thanks for your help allen, as mentioned above i only get the error if the table TestData is empty. if i add a book the linq query works fine. maybe you try it without the AddNewBook() method and then get the exception.

    greatz
    flo
    Yes, i'm living in the cloud
    Friday, December 4, 2009 11:32 AM
  • Hi,

    Thanks for your update. I deleted all entities in TestData table, commented the call of AddNewBook() but still cannot get the exception with your code. Could you double check it?

    Can anyone else reproduce this issue?
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, December 7, 2009 6:08 AM
  • thanks for your effort allen.
    i did a workaround in my case (got the exception when the table i want to query is empty) with a try-catch block and catched the specific exception which will be thrown if the table is empty...

    but if anybody detects the source of the error, please let me know how i can solve the problem in a better way

    greatz
    flo
    Yes, i'm living in the cloud
    Wednesday, December 9, 2009 3:18 PM
  • Hi

    I have the same problem.

    I have installed Windows Azure November 2009 Update and migrated AzureTodoList sample application http://dotnetslackers.com/articles/aspnet/building-applications-for-windows-azure.aspx to use the latest API. On empty tables every select query with where clause causes the DataServiceQueryException exception. When I added some record to the table everything works fine.


    Best Regards
    Alex

    Thursday, December 24, 2009 9:45 PM
  • Hi guys,

     

    I also had the problem described here and after a lot of Googling around I found an explanation and solution in this blog post. I hope this will save someone the pain of figuring things on his own.

     

    In short, the solution is to set the TableServiceContext.IgnoreResourceNotFoundException property to "true".

     

    Edit: You can also check if a table is empty like so:

    private bool IsTableEmpty()
    {
      var e = this.CreateQuery<MyDataType>(myTableName).GetEnumerator();
      return !e.MoveNext();
    }

    Friday, September 17, 2010 9:07 AM