Auto-Complete Proble

Hi guys, what is wrong with my code? I followed a certain article but it uses MS SQL but it doesn’t works.
Here’s my code for my webservice


/// <summary>
/// Summary description for acPatientList
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class acPatientList : System.Web.Services.WebService {

    public acPatientList () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string[] GetPatientList(string strPrefixText) 
    {
        MySqlConnection cnDBConnection = new MySqlConnection();
        MySqlCommand cmPatientList = new MySqlCommand();
        MySqlDataReader rdPatientList;

        List <string> result = new List<string>();
        
        cnDBConnection.ConnectionString = clsFunction.strConnection;
        cnDBConnection.Open();
        cmPatientList.Connection = cnDBConnection;
        cmPatientList.CommandText = "SELECT patientid, CONCAT(lname,', ',fname,' ',mname) " +
                                    "patientlist WHERE lname LIKE '" +
                                    clsFunction.ReplaceString(strPrefixText) + "%'";
        rdPatientList = cmPatientList.ExecuteReader();
        
        while(rdPatientList.Read())
        {
            result.Add(rdPatientList[0].ToString() + "-" + rdPatientList[1].ToString());
        }
        
        return result.ToArray();
        cnDBConnection.Close();


    }
    
}

And here’s the attributes for my control

<cc1:AutoCompleteExtender ID="AutoCompleteExtender" runat="server" ServiceMethod="GetPatientList"
             ServicePath="acPatientList.asmx"  MinimumPrefixLength="1" TargetControlID="txtPatientName" UseContextKey="True">

First of all, you need to change this:


return result.ToArray();
cnDBConnection.Close();

To:


cnDBConnection.Close();
return result.ToArray();

You need to close the connection, before returning the data. Or else, the close connection will never execute. Open connection = Not good.

EDIT:

Close the Command object also, before the “return”.

I followed your instruction USPatriot but, still it doesn’t work .

He was not answering your question, just pointing out another problem all together that would cause bigger problems in the long run.

In the past when I still used MS Ajax, I had endless issues with this control. It worked, but very slowly. I have since then moved to the jQuery solution for this and it works MUCH better and faster.

This the result of my web service when i invoke it


<?xml version="1.0" encoding="utf-8" ?> 
- <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <string>000003-Ubando, Michael Cruz</string> 
  </ArrayOfString>

However, when it comes to my textbox, it doesn’t display anything.

Do you have firebug installed in your firefox? If so, open up the consolse and start typing and see what the response is there and if all is working ok

Well, I’m not using firefox…instead I use IE 8

Try using FF and see if it works, and if not. Use firebugs console to try and debug the issue. There are dev sorta tools like firebug for IE, but not sure how well they work

Here’s an error from IE based on its status bar…

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
Timestamp: Fri, 15 Jan 2010 13:27:11 UTC

Message: ‘Sys’ is undefined
Line: 61
Char: 1
Code: 0
URI: http://localhost:61942/prms/requestform.aspx

Sys is the core bit of MSAJAX, so it means you’ve got some error that is either blowing up msajax or it isn’t getting loaded in IE.