locked
InvalidInput error when trying to delete a Table entity RRS feed

  • Question

  • I am running locally in Visual Studio. I have created a table and inserted entities into it and read them out. If I try and delete an entity that I have read it works but if I try and specify an entity to delete using partition and row keys (and Timestamp) I get this error. (followed by my code at end)  

    Server Error in '/' Application.

    <?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="en-CA">One of the request inputs is not valid.</message>
    </error>

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: 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="en-CA">One of the request inputs is not valid.</message>
    </error>

    Source Error:

    Line 71:       _context.DeleteObject(itemToDelete);
    Line 72:       SaveChangesOptions ops = SaveChangesOptions.ContinueOnError;
    Line 73:       DataServiceResponse dataServiceResponse = _context.SaveChanges(ops);
    Line 74: 
    Line 75:       Trace.WriteLine(dataServiceResponse.Count());

    Source File: C:\Dev\HelloCloud\WorkerRole1\TableStorage\ProductDataService.cs    Line: 73

    Stack Trace:

    [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="en-CA">One of the request inputs is not valid.</message>
    </error>]
      System.Data.Services.Client.<HandleBatchResponse>d__1e.MoveNext() +1864
    
    [DataServiceRequestException: An error occurred while processing this request.]
      System.Data.Services.Client.SaveResult.HandleBatchResponse() +637228
      System.Data.Services.Client.SaveResult.EndRequest() +302
      System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) +184
      WorkerRole1.TableStorage.ProductDataService.Delete(PhoneEntity itemToDelete, Boolean attached) in C:\Dev\HelloCloud\WorkerRole1\TableStorage\ProductDataService.cs:73
      WorkerRole1.WorkerRole.DeletePhone(String partitionKey, String rowKey, DateTime stamp) in C:\Dev\HelloCloud\WorkerRole1\WorkerRole.cs:117
      WebRole1._Default.Clicked(Object sender, GridViewCancelEditEventArgs e) in C:\Dev\HelloCloud\WebRole1\Default.aspx.cs:58
      System.Web.UI.WebControls.GridView.HandleCancel(Int32 rowIndex) +84
      System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +569
      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691
    

     


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

     

     

     

    public void Delete(PhoneEntity itemToDelete, bool attached)

    {

     

     

    if (!attached)

    _context.AttachTo(

     

    ProductDataServiceContext.ProductTableName, itemToDelete);

    _context.DeleteObject(itemToDelete);

     

     

    DataServiceResponse dataServiceResponse = _context.SaveChanges();

    }

     


    woaksie
    Wednesday, November 10, 2010 7:00 PM

Answers

  • I suspect you need _context.AttachTo(ProductDataServiceContext.ProductTableName, itemToDelete, "*");

    The last parameter is an ETag and means to delete no matter what the ETag is.

    The documentation for deleting an entity (http://msdn.microsoft.com/en-us/library/dd135727.aspx) says that If-Match is a required header (and that's where the ETag goes).

    • Marked as answer by Mog Liang Thursday, November 18, 2010 10:08 AM
    Thursday, November 11, 2010 8:09 AM

All replies

  •     public void Delete(PhoneEntity itemToDelete, bool attached)
        {
          if (!attached)
            _context.AttachTo(ProductDataServiceContext.ProductTableName, itemToDelete);
    
          _context.DeleteObject(itemToDelete);
          DataServiceResponse dataServiceResponse = _context.SaveChanges();
        }
    
    

    This is the code segment again. So this works when I read a PhoneEntity from the Table (and pass attached = True) but fails when I create a PhoneEntity myself and set the partition and row key values and pass attached = False.

    I guess this leads on to how to debug problems like this. Is there a log I can access, or performance counters that might help. I have been using Trace.WriteLine for my own code but when something goes wrong in the "cloud" what are the best ways to find out what went wrong. The error messages in this case are no help at all.


    woaksie
    Wednesday, November 10, 2010 7:08 PM
  • I recommend you use Fiddler to see precisely what is sent over the wire to Azure Storage. This is usually very helpful in isolating the problem. Adam Sampson has a post showing how to configure the connection string to work with Fiddler in the development environment.
    Wednesday, November 10, 2010 7:33 PM
    Answerer
  • I suspect you need _context.AttachTo(ProductDataServiceContext.ProductTableName, itemToDelete, "*");

    The last parameter is an ETag and means to delete no matter what the ETag is.

    The documentation for deleting an entity (http://msdn.microsoft.com/en-us/library/dd135727.aspx) says that If-Match is a required header (and that's where the ETag goes).

    • Marked as answer by Mog Liang Thursday, November 18, 2010 10:08 AM
    Thursday, November 11, 2010 8:09 AM