locked
Winodws Azure CreateQuery not working RRS feed

  • Question

  • Hi All,

    I am trying to execute a very simple query and I am getting some very strange results.  Here is what I'm doing.

    Command 1:

     

     

    Dim LockTableItems As List(Of LockTableItem) = (From LockTableItem As LockTableItem In context.CreateQuery(Of LockTableItem)("UserRegister0Lock") Where ((LockTableItem.RowKey = "UserRegister_batmanbond3dd%40hotmail.com_"))).ToList

    This is working as expected and is returning one result as it should.

    Command 2:

     

     

    Dim LockTableItems As List(Of LockTableItem) = (From LockTableItem As LockTableItem In context.CreateQuery(Of LockTableItem)("UserRegister0Lock") Where ((LockTableItem.PartitionKey = "batmanbond3dd%40hotmail.com"))).ToList

    This is working as expected and is returning one result as it should.

    Command 3:

     

     

    Dim LockTableItems As List(Of LockTableItem) = (From LockTableItem As LockTableItem In context.CreateQuery(Of LockTableItem)("UserRegister0Lock") Where ((LockTableItem.RowKey = "UserRegister_batmanbond3dd%40hotmail.com_") And (LockTableItem.PartitionKey = "batmanbond3dd%40hotmail.com"))).ToList

    This command is throwing the exception:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
      <code>ResourceNotFound</code>
      <message xml:lang="en-CA">The specified resource does not exist.</message>
    </error>

    I do not know why Command 3 is throwing an exception.  All I did was aggregate the PartitionKey query and the RowKey query and for some reason it Winodws Azure Client library can not process it.  Any ideas to what I am doing wrong.

    Friday, February 11, 2011 1:26 AM

Answers

  • Well it seems to me that having nonalphanumeric values as in your partitionkey or rowkey will cause strange bugs to appear using the REST API.  What I did as a workaround was create a function that converts any string into a pure alphanumeric string with the underscore accepted as well.  For anyone interrested here is a function that will do so.

      Public Shared Function ConvertToBaseEight(ByVal Value As Integer) As String
        If Value = 0 Then
          Return "0"
        End If
        Dim Result As String = ""
        While Value <> 0
          Dim tMod = Value And &H7
          Value >>= 3
          Result = tMod & Result
        End While
        Return Result
      End Function
    
      Public Shared Function ConvertFromBaseEight(ByVal Value As String) As Integer
        Dim Result As Integer = 0
        For i As Integer = Value.Length To 1 Step -1
          Dim Num As Integer = Asc(Mid(Value, i, 1)) - Asc("0")
          Result = Result << 3
          Result = Result And Num
        Next
        Return Result
      End Function
    
      Public Shared Function ConvertToAlphaNumeric(ByVal Value As String) As String
        Dim Result As New StringBuilder
        For I As Integer = 1 To Value.Length
          Dim TVal As String = Mid(Value, I, 1)
          Dim CCode As Integer = Asc(TVal)
          If (CCode >= Asc("a") AndAlso CCode <= Asc("z")) OrElse (CCode >= Asc("A") AndAlso CCode <= Asc("Z") AndAlso CCode <> Asc("Q")) OrElse (CCode >= Asc("0") AndAlso CCode <= Asc("9")) OrElse CCode = Asc("_") Then
            Result.Append(TVal)
          Else
            Result.Append("Q")
            Result.Append(ConvertToBaseEight(CCode))
            Result.Append("Q")
          End If
        Next
        Return Result.ToString()
      End Function
    
      Public Shared Function ConvertFromAlphaNumeric(ByVal Value As String) As String
        Dim Result As New StringBuilder
        For I As Integer = 1 To Value.Length
          Dim TVal As String = Mid(Value, I, 1)
          Dim CCode As Integer = Asc(TVal)
          If (CCode >= Asc("a") AndAlso CCode <= Asc("z")) OrElse (CCode >= Asc("A") AndAlso CCode <= Asc("Z") AndAlso CCode <> Asc("Q")) OrElse (CCode >= Asc("0") AndAlso CCode <= Asc("9")) OrElse CCode = Asc("_") Then
            Result.Append(TVal)
          ElseIf CCode = Asc("Q") Then
            I += 1
            Dim ClosingQPosition As Integer = InStr(I, Value, "Q")
            If ClosingQPosition = 0 Then
              Throw New Exception("Value was not in proper form in ConvertFromAlphaNumeric")
            Else
              Result.Append(ConvertFromBaseEight(Mid(Value, I, ClosingQPosition - 1 - I)))
            End If
            I = ClosingQPosition
          Else
            Throw New Exception("Value was not in proper form in ConvertFromAlphaNumeric")
          End If
        Next
        Return Result.ToString()
      End Function
    

     

    • Marked as answer by Mog Liang Friday, February 18, 2011 9:53 AM
    Friday, February 11, 2011 4:24 PM

All replies

  • Is there an entity with that partition key and row key?  You may want to use context.IgnoreResourceNotFoundException = true.

    Friday, February 11, 2011 4:02 AM
  • Yes I'm 100% sure that the entity exists.  Command 1 and Command 2 prove it's existance as command 1 and command 2 return the exact same result which is the only element inside that table.  The result I'm expecting is the same result as Command 1 and Command 2.

    Friday, February 11, 2011 4:14 AM
  • Are you using .NET 3.5 or .NET 4?

    The next thing I would do is run Fiddler (http://fiddler2.com) and watch the HTTP traffic.  See if anything looks broken in the last query.  (I suspect an issue with the encoding of the URL.  There were known issues in the .NET 3.5 WCF Data Services library, which is why I'm asking which version you're using.)

    Friday, February 11, 2011 6:01 AM
  • I am using .NET 4.  Fiddler does not seem to be capturing anything coming from windows azure.  Note that my PartitionKey and RowKey have non alphanumeric values.  Can you perhaps try to create a table with the primarykey and rowkey which I specified and see if that causes an error when you do a createquery?  Perhaps windows azure table storage is still a bit buggy when the partitionkey or rowkey contains non alphanumeric values.
    Friday, February 11, 2011 6:56 AM
  • Well it seems to me that having nonalphanumeric values as in your partitionkey or rowkey will cause strange bugs to appear using the REST API.  What I did as a workaround was create a function that converts any string into a pure alphanumeric string with the underscore accepted as well.  For anyone interrested here is a function that will do so.

      Public Shared Function ConvertToBaseEight(ByVal Value As Integer) As String
        If Value = 0 Then
          Return "0"
        End If
        Dim Result As String = ""
        While Value <> 0
          Dim tMod = Value And &H7
          Value >>= 3
          Result = tMod & Result
        End While
        Return Result
      End Function
    
      Public Shared Function ConvertFromBaseEight(ByVal Value As String) As Integer
        Dim Result As Integer = 0
        For i As Integer = Value.Length To 1 Step -1
          Dim Num As Integer = Asc(Mid(Value, i, 1)) - Asc("0")
          Result = Result << 3
          Result = Result And Num
        Next
        Return Result
      End Function
    
      Public Shared Function ConvertToAlphaNumeric(ByVal Value As String) As String
        Dim Result As New StringBuilder
        For I As Integer = 1 To Value.Length
          Dim TVal As String = Mid(Value, I, 1)
          Dim CCode As Integer = Asc(TVal)
          If (CCode >= Asc("a") AndAlso CCode <= Asc("z")) OrElse (CCode >= Asc("A") AndAlso CCode <= Asc("Z") AndAlso CCode <> Asc("Q")) OrElse (CCode >= Asc("0") AndAlso CCode <= Asc("9")) OrElse CCode = Asc("_") Then
            Result.Append(TVal)
          Else
            Result.Append("Q")
            Result.Append(ConvertToBaseEight(CCode))
            Result.Append("Q")
          End If
        Next
        Return Result.ToString()
      End Function
    
      Public Shared Function ConvertFromAlphaNumeric(ByVal Value As String) As String
        Dim Result As New StringBuilder
        For I As Integer = 1 To Value.Length
          Dim TVal As String = Mid(Value, I, 1)
          Dim CCode As Integer = Asc(TVal)
          If (CCode >= Asc("a") AndAlso CCode <= Asc("z")) OrElse (CCode >= Asc("A") AndAlso CCode <= Asc("Z") AndAlso CCode <> Asc("Q")) OrElse (CCode >= Asc("0") AndAlso CCode <= Asc("9")) OrElse CCode = Asc("_") Then
            Result.Append(TVal)
          ElseIf CCode = Asc("Q") Then
            I += 1
            Dim ClosingQPosition As Integer = InStr(I, Value, "Q")
            If ClosingQPosition = 0 Then
              Throw New Exception("Value was not in proper form in ConvertFromAlphaNumeric")
            Else
              Result.Append(ConvertFromBaseEight(Mid(Value, I, ClosingQPosition - 1 - I)))
            End If
            I = ClosingQPosition
          Else
            Throw New Exception("Value was not in proper form in ConvertFromAlphaNumeric")
          End If
        Next
        Return Result.ToString()
      End Function
    

     

    • Marked as answer by Mog Liang Friday, February 18, 2011 9:53 AM
    Friday, February 11, 2011 4:24 PM