Click here to Skip to main content
15,886,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My asmx code is for two textboxes... those are specialization and location.
Now it is working in localhost but not working after hosting my domain...
anyone pls help me out... Thank You

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]

public class AutoCompleteWebService : System.Web.Services.WebService {

    public AutoCompleteWebService () {

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

    [WebMethod]
      public string[] AutoCompleteAjaxRequest(string prefixText, int count)
        {

            List<string> ajaxDataCollection = new List<string>();
            DataTable _objdt = new DataTable();
            _objdt = GetDataFromDataBase(prefixText);
                if(_objdt.Rows.Count>0)
                {
                    for (int i = 0; i < _objdt.Rows.Count; i++)
                    {
                        ajaxDataCollection.Add(_objdt.Rows[i]["spename"].ToString());
                    }
                }
            return ajaxDataCollection.ToArray();
        }
    public DataTable GetDataFromDataBase(string prefixText)
    {
         
        string connectionstring = "Data Source=localhost;Initial Catalog=DoctorAppointment;User ID=sa;Password=abc;";
        DataTable _objdt = new DataTable();
        string querystring = "select spename from tbl_spe where spename like '%" + prefixText + "%';";
        SqlConnection _objcon = new SqlConnection(connectionstring);
        SqlDataAdapter _objda = new SqlDataAdapter(querystring, _objcon);
        _objcon.Open();
        _objda.Fill(_objdt);
        return _objdt;
    }
    [WebMethod]
    public string[] AutoCompleteAjaxRequestLoc(string prefixText, int count)
    {
        List<string> ajaxDataCollection = new List<string>();
        DataTable _objdt = new DataTable();
        _objdt = GetDataFromDataBase1(prefixText);
        if (_objdt.Rows.Count > 0)
        {
            for (int i = 0; i < _objdt.Rows.Count; i++)
            {
                ajaxDataCollection.Add(_objdt.Rows[i]["loc"].ToString());
            }
            
        }
        return ajaxDataCollection.ToArray();
    }
    public DataTable GetDataFromDataBase1(string prefixText)
    {
        string connectionstring = "Data Source=localhost;Initial Catalog=DoctorAppointment;User ID=sa;Password=abc;";
        DataTable _objdt = new DataTable();
        string querystring = "select loc from tbl_loc where loc like '%" + prefixText + "%';";
        SqlConnection _objcon = new SqlConnection(connectionstring);
        SqlDataAdapter _objda = new SqlDataAdapter(querystring, _objcon);
        _objcon.Open();
        _objda.Fill(_objdt);
        return _objdt;
    }
Posted
Comments
F-ES Sitecore 31-Jul-15 7:43am    
Use the dev tools of your browser, or a tool like Fiddler, to examine the network calls to see if that gives any indication about what the problem might be.
Richard Deeming 31-Jul-15 7:47am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Sreekanth Mothukuru 1-Aug-15 2:23am    
Post code on how you are calling your asmx service methods..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900