locked
DataService DB query - Bad Request - Error in query syntax. RRS feed

  • Question

  • I'm getting this inner exception to an EndpointNotFoundException:

    "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><error xmlns=\"<message">http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\"><code></code><message xml:lang=\"en-US\">Bad Request - Error in query syntax.</message></error>"

    Here is the service code:

        public class SupportFunctions : DataService< A.Certain.Namespace.DataModel.MyEntities>
        {
            //// This method is called only once to initialize service-wide policies.
            public static void InitializeService(DataServiceConfiguration config)
            {
                config.SetEntitySetAccessRule("*", EntitySetRights.All);
                config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
               // config.UseVerboseErrors = true;
            }
        }

    MyContextImpl dataContext = new MyContextImpl();

    MyTableName tableTest = dataContext.TableName.Where(m => m.ID == 100).FirstOrDefault();

    tableTest.OtherValue = "B";

    dataContext.UpdateObject(tableTest);

    dataContext.SaveChanges();

    I have changed the names, but what is being done is the same.

    I can't post all the code as this is a huge project.

    But I can give more details if you ask.

    Some google searches I found said that one fix to this problem

    (in certain instances I assume) is to specify the URI query

    explicitly, but I've tried to find how to do that and haven't found anything

    yet.  Anyways, the table actually has other columns in it that I didn't

    specify when I pulled it out of the database or changed the values, but they would still be part of the update query according to what I saw when I looked at values in watch.  There was a DateTime involved, there were some null values in the database but I don't see how that would create a problem because it's not like I'm adding a new row with null values being inserted into non-null columns.

    Anyways, if you want more details I can give them, and if you don't know what could be causing this but you still know how I can make a specific query with a specified URL string, then I could try that.

    I will mark as answer if you solve my problem, or mark as helpful if you give me some insight into this that I think could help me understand this better so I can figure out this sucker. 

           

    Tuesday, June 4, 2013 10:09 PM

All replies

  • On 6/4/2013 6:09 PM, jamesiw wrote:

    I'm getting this inner exception to an EndpointNotFoundException:

    The error means that the client program cannot find the data-service program that it's looking for, the endpoint. It may be due to the data-service is not running or the URI or URL is incorrect with the given information to locate the data-service. It could be that a firewall is blocking on the inbound port the data-service is listening on, and the client cannot make contact.

    http://msdn.microsoft.com/en-us/library/gg258442.aspx

    Did you ever test the dataservice to see if it works by using a browser and giving the URI in the browser address like? If it doesn't show the XML schema in the browser, the data-service is not working and running.

    Wednesday, June 5, 2013 12:16 AM
  • But doesn't the inner exception indicate that the reason the endpoint is not found is because of the database query syntax, in other words the address may be correct if you neglected the query?  That's what I would have thought anyways, but I'll try tomorrow morning to see if the service is running.  I've been through similar types of errors where I couldn't access the service because it wasn't running and I tried putting the address into the browser to see if I could access it, or where it was running but there was a wrong address specified or where the domain wasn't specified.  It skipped my mind to do that this time because I was focusing on the inner exception, not the exception itself.  I will try seeing if I can get the service in the browser tomorrow when I get to work.

      Thanks.

    Wednesday, June 5, 2013 5:12 AM
  • OK, well the service is running and it has the table name in an xml tag when I load thebrowser, but I'm ondering how do I get at the query that is being exectuted?  In my code,the debugger throws the eception at the SaveChanges line, even though it's really not there,it's inside the Microsoft code where the exception gets thrown, but don't think I can set breakpoints there.  So how can I examine my query what the query error is that's causing the exception?  Wouldn't it be the query in this case since the service is running?

    Wednesday, June 5, 2013 1:25 PM
  •  <http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx>
      Other than what's in the link, you are going to have to search Bing or Google to find out what is happening with a restful WCF service using a database with Linq.

    I have used a Restful WCF service with Linq and Entity Framework. Have you considered using an ORM?

    Here is a tool that may help you debug an Odata-service if using an ORM like EF.
     http://www.linqpad.net/

    Wednesday, June 5, 2013 1:44 PM
  • It's actually a DataServiceRequestException now, with the same inner exception. The code that I posted remains the same in my project, but something else must have changed somewhere.  But previously I was able to see the query string when I examined dataContext in watch, now I only see the address.  And I'm the database row is still there, the updateobject and savechanges are still being called, but I've been putting the breakpoint on savechanges before the exception gets thrown so savechanges isn't getting called when I'm examining watch.
    Wednesday, June 5, 2013 1:46 PM