locked
How to get error message in detail when using ADO.NET Data service to save data into database? RRS feed

  • Question

  • When using ADO.NET Data service to save data into database such update/Insert/Delete, if there operation is failed, the error message from DataServiceRequestException is kind of generic message like

    An error occurred while processing this request.
    System.Data.Services.Client.DataServiceResponse

    Internally, it's like
    "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"yes\"?>\r\n<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n  <code></code>\r\n  <message xml:lang=\"en-CA\">An error occurred while processing this request.</message>\r\n</error>\r\n"

    There is no detail why this operation is failed.

    How to get the error in detail?
    Wednesday, January 14, 2009 3:23 PM

Answers

All replies

  • Hi KetZhou,
     Please take a look at this blog post which talks about how to enable Detailed error messages when developing ADO.NET Data Services http://blogs.msdn.com/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx
    Phani Raj Astoria
    • Proposed as answer by Phani Raju MSFTModerator Wednesday, January 14, 2009 5:12 PM
    • Marked as answer by Phani Raju MSFTModerator Wednesday, January 14, 2009 5:12 PM
    • Unmarked as answer by KentZhou Wednesday, January 14, 2009 7:43 PM
    • Unproposed as answer by KentZhou Wednesday, January 14, 2009 7:44 PM
    • Marked as answer by KentZhou Friday, January 16, 2009 1:14 AM
    Wednesday, January 14, 2009 5:12 PM
    Moderator
  • Hello,

    From the client API perspective here is an example on how to deal with DataServiceRequestException:

    EntityDescriptor entity;

    LinkDescriptor link;

    try { ...}
    catch
    (DataServiceRequestException se)
    {
        foreach (ChangeOperationResponse changeset in se.Response)
       {
             if (changset.Error != null)
                {
                    throw changset.Error;
                }
     

            if (changset.Descriptor is System.Data.Services.Client.EntityDescriptor)
            {
                entity = (EntityDescriptor)changeset.Descriptor;
           
     }
            else if (changset.Descriptor  is System.Data.Services.Client.LinkDescriptor)
            {

                link = (LinkDescriptor)changeset.Descriptor;
            }
                ....

        }
        
        }
    }


    Hote this helps.

    Regards,
    Monica Frintu

    Wednesday, January 14, 2009 6:38 PM
    Moderator
  • Phani Raju MSFT said:

    Hi KetZhou,
     Please take a look at this blog post which talks about how to enable Detailed error messages when developing ADO.NET Data Services http://blogs.msdn.com/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx


    Phani Raj Astoria

    Thanks. I follow your guide one by one:
    1. Modified Web.config:
     <system.serviceModel>
        <services>
          <service name="MySite.Web.Service1"  behaviorConfiguration ="DebugEnabled">
          </service>
        </services>
        <behaviors>
          <serviceBehaviors >
            <behavior name="DebugEnabled">
              <serviceDebug includeExceptionDetailInFaults="True"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      </system.serviceModel>

    2. Add code to InitializeService:
    config.UseVerboseErrors = true;   

    3. Then Catch the exception like:
    try
    {
      //....
      svcx.EndSaveChanges(result);
    //....
    }
    catch (DataServiceRequestException ex)
    {
      Debug.WriteLine("OnSaveChangesCompleted Error: " + ex.Response.ToString());
    }
    catch (Exception ex)
    {
      Debug.WriteLine("OnSaveChangesCompleted Error: " + ex.ToString());
    }

    But still get error message with no detail.


    Wednesday, January 14, 2009 6:53 PM
  • Thanks, Monica Frintu. I tried you code after make changes based on Phani Raju's advices, and got exception at first time at
    if (changset.Error != null)
       {
          throw changset.Error;
       }


    Then checking changset.Error in debug mode, no error message in detail, only generic error message as before. 
    Wednesday, January 14, 2009 6:55 PM
  • Hi Kent,
     Can you please try getting a Fiddler trace of the request/response ?
     Fiddler can be downloaded here : http://www.fiddlertool.com

    Phani Raj Astoria
    Wednesday, January 14, 2009 8:56 PM
    Moderator