locked
Illegal characters in where clause causes DataServiceQueryException? RRS feed

  • General discussion

  • Hello. I have a simple dataservice setup for access to my database. When I execute the following query on a client:

    item = ctx.Items.Where(i => i.itemID == productID).FirstOrDefault();

    this seems to fail whenever the productID var contains a '&' character. I can imagine what causes it (& characters in a querystring usually means trouble), but I'm not sure how to fix it. Maybe using some escaping will fix it, but that would mean I have to alter my code on numerous places with the risk of forgetting some statements.

    What's the proper way of dealing with this?
    MCTS in Web Application Development in .NET 2.0
    this.context.Items.Where(i => i.ERPID == productID).FirstOrDefault();
    Tuesday, July 21, 2009 8:08 PM

All replies

  • This is a known bug that we are expecting to fix in the next version. The problem is that there are certain characters we are not escaping inside of data values passed to a query - the service is then trying to escape those characters and as a result is failing the query. The only way to get passed this issue is to call System.Uri.EscapeDataString on your data values before passing them to the query.

    Thanks,
    Shayne
    Saturday, August 8, 2009 8:20 PM
    Moderator
  • Hi Shayne,

    is the call going to succeed when I only escape the string at the client side? Or do I need to do something at serverside too?
    MCTS in Web Application Development in .NET 2.0
    Tuesday, August 11, 2009 8:11 AM
  • The calls should start working if you just escape the data strings on the client side; the server will parse the result correctly.

    Shayne

    Wednesday, August 12, 2009 3:19 AM
    Moderator