Problem with code RRS feed

  • Question

  • Hopefully a fresh set of eyes may help and spot where I am going wrong. I'm using a SQLCLR database project and trying to update the contact entity. I have a custom field in contact called new_webid which is a whole number. When trying to do a lookup in the code below,  as soon as it hits the for each loop it errors with '1 ----- Server was unable to process request.'

    I have tried hardcoding in valid new_webid but still get the same results. I must be overlooking something but cannot see what

        <Microsoft.SqlServer.Server.SqlProcedure()> _
        Public Shared Sub RegisteredUsers_Delete_vb(intID As SqlInt32)
            Dim token As New CrmAuthenticationToken()
            token.AuthenticationType = 0
            token.OrganizationName = "XXXXX"
            Using crmService As New CrmService()
                    Dim YesBoolean As New CrmBoolean
                    Dim NoBoolean As New CrmBoolean
                    YesBoolean.Value = True
                    NoBoolean.Value = False
                    crmService.Url = "https://XXX.XXX.XX:XXX/MSCRMServices/2007/CrmService.asmx"
                    crmService.Credentials = New System.Net.NetworkCredential("XXX", "XXX", "XXX")
                    crmService.CrmAuthenticationTokenValue = token
                    crmService.UnsafeAuthenticatedConnectionSharing = True
                    crmService.PreAuthenticate = True
                    Dim WebID As New CrmNumber()
                    WebID.Value = intID.Value
                    ' Get Lookup
                    Dim _queryattr As New QueryByAttribute()
                    _queryattr.EntityName = "contact"
                    Dim _columns As New ColumnSet()
                    _columns.Attributes = New String() {"contactid"}
                    _queryattr.ColumnSet = _columns
                    _queryattr.Attributes = New String() {"new_webappid"}
                    _queryattr.Values = New CrmNumber() {WebID}
                    Dim rResultSet As BusinessEntityCollection = crmService.RetrieveMultiple(_queryattr)
                    For Each ncontact As contact In rResultSet.BusinessEntities
                        Using sw As New StreamWriter(LOGFILEPATH & "trig_RegisteredUser.txt", True)
                            sw.WriteLine("2 ----- " & ncontact.contactid.Value.ToString)
                        End Using
                        ' Is Active
                        ncontact.new_accountactive = NoBoolean
                        Exit For
                Catch ex As Exception
                    Using sw As New StreamWriter(LOGFilePath & "trig_RegisteredUser.txt", True)
                        sw.WriteLine("1 ----- " & ex.Message.ToString)
                    End Using
                End Try
            End Using
        End Sub

    Dont ask me .. i dont know

    Tuesday, August 13, 2013 4:33 PM

All replies

  • the values line where you are making an object of crmnumber could be the issue. can you try using object array instead.

    also to get additional details and a more descriptive error catch soapexception



    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Wednesday, August 14, 2013 12:00 AM
    • Unproposed as answer by Pete Newman Wednesday, August 14, 2013 8:56 AM
    Wednesday, August 14, 2013 12:00 AM
  • HI,

    I have been going round in circles. I have been trying to get some more information on the error but there is nothing in the SQL logs. I think you may be right with he values issue as I have managed to find where it errors out. its the line

    Dim rResultSet As BusinessEntityCollection = crmService.RetrieveMultiple(_queryattr)
    I am presuming its the setting of the value for new_webappid.  In SQL it is an integer and in CRM its a number.  There must be a way that i can get the contactid from the new_webappid value

    Dont ask me .. i dont know

    • Edited by Pete Newman Wednesday, August 14, 2013 8:56 AM spelling of field name was wrong
    Wednesday, August 14, 2013 8:37 AM