0

I have an an autocomplete extender on my page that searches a database based on last name. For some reason when searching "Smith" which should return 1564 results nothing is being returned? When I search other names it works fine "Jones" etc. I am thinking "Smith" has the most rows and there is a limit or something? Any ideas?

 <asp:TextBox ID="DoctorNameTextBox" runat="server" Height="24px" Width="739px" 
            Font-Size="Small"></asp:TextBox>
        <asp:AutoCompleteExtender ID="AutoCompleteExtender" runat="server" 
    DelimiterCharacters="" Enabled="True" ServicePath="AutoComplete.asmx" 
            ServiceMethod="GetCompletionList" TargetControlID="DoctorNameTextBox" 
    MinimumPrefixLength="2" UseContextKey="true" ContextKey="StateDropDown"
            CompletionListElementID="autocompleteDropDownPanel" 
            onclientitemselected="getSelected" CompletionSetCount="20" 
            ShowOnlyCurrentWordInCompletionListItem="True">

Public Function GetCompletionList(prefixText As String, count As Integer, ByVal contextKey As String) As String()
    Try
        Dim Con As SqlConnection
        Dim cmd As SqlCommand
        Con = New SqlConnection
        Dim test As String
        test = contextKey
        Con.ConnectionString = ""
        Con.Open()

        cmd = New SqlCommand
        cmd.Connection = Con
        cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)], [Provider First Name],[Provider First Line Business Mailing Address], [Provider Business Mailing Address City Name], [Provider Business Mailing Address State Name], [Provider Business Mailing Address Postal Code] FROM NPIData WHERE   ([Provider Business Mailing Address State Name] = @State) AND ([Provider Last Name (Legal Name)] LIKE N'%' + @Provider + N'%') ORDER BY [Provider First Name]"
        cmd.Parameters.AddWithValue("@Provider", prefixText)
        cmd.Parameters.AddWithValue("@State", contextKey)
        Dim customers As List(Of String) = New List(Of String)
        Dim reader As SqlDataReader = cmd.ExecuteReader()


        While reader.Read
            customers.Add(reader("Provider Last Name (Legal Name)").ToString + ", " + reader("Provider First Name").ToString + "   " + reader("Provider First Line Business Mailing Address").ToString + "  " + reader("Provider Business Mailing Address City Name").ToString + ", " + reader("Provider Business Mailing Address State Name").ToString + "  " + reader("Provider Business Mailing Address Postal Code").ToString + "  " + reader("NPI").ToString)

        End While


        Con.Close()

        Return customers.ToArray
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

End Function
user1342164
  • 1,434
  • 13
  • 44
  • 83
  • Do you see any errors in the console log? Load your page with Chrome and press F12. Then click on console and see if any errors are displayed – Icarus Jul 31 '13 at 18:39
  • Under Response Body tab it says {"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""} – user1342164 Jul 31 '13 at 18:43
  • Debug the application and put a break point in the web service method and see why is failing. – Icarus Jul 31 '13 at 18:45
  • I did and there are no errors happening, it even shows the results in the debug window – user1342164 Jul 31 '13 at 18:50
  • 1
    I think you are hitting the jsonSerialization limit. Try returning only the first 500 records, and see if the problem disappears. If so, you can extend the limit in the Web.config but in this case I wouldn't bother. **No body will ever go through a list of more than 20 suggestions any way.** – Icarus Jul 31 '13 at 19:29
  • How can I extend it in the web config? – user1342164 Jul 31 '13 at 19:41
  • 1
    See here: http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config – Icarus Jul 31 '13 at 19:45
  • I will submit an answer for reference to other people looking for a solution to this problem. – Icarus Jul 31 '13 at 19:54

1 Answers1

2

When the list returned by the Web Service exceeds the max jsonSerialization limit of 102400 (string length), the AutoCompleteExtender fails silently. A way to "fix" this (although is not practical) is to increase the value in the web.config as so:

Make sure you have this section in your sectionGroup section. If you don't, add it.

<sectionGroup name="system.web.extensions" type="System.Web.Extensions">
    <sectionGroup name="scripting" type="System.Web.Extensions">
         <sectionGroup name="webServices" type="System.Web.Extensions">
                  <section name="jsonSerialization" type="System.Web.Extensions"/>
          </sectionGroup>
    </sectionGroup>
</sectionGroup> 

And then set the value:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 

See this other answer.

Community
  • 1
  • 1
Icarus
  • 63,293
  • 14
  • 100
  • 115