Hello, I created Ajax cascadingdownload list in my project. It worked fine in my localhost but when deployed it to my university's web server, the method error 500 was shown on page loaded. so the Firebug told me that the error is coming form "Conversion
failed when converting the nvarchar value 'BindCategory' to datatype Int." My code is below:
using System.Data;
using System.Web.Services;
using System.Collections.Generic;
using System.Collections.Specialized;
using AjaxControlToolkit;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Script.Services;
/// <summary>
/// Summary description for CascadingDropdown
/// </summary>
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
//[WebService(Namespace = "http://www.stou.ac.th/Offices/ore/rere/goto/HelpDeskAdmin/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[System.Web.Script.Services.ScriptService]
//[System.Web.Script.Services.ScriptService()]
public class CascadingDropdown : System.Web.Services.WebService
{
[WebMethod]
public CascadingDropDownNameValue[] BindCategory(string knownCategoryValues, string category)
{
SqlConnection concatname = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString);
concatname.Open();
SqlCommand cmdcatname = new SqlCommand("select * from HelpDeskCat where IsActive = 1", concatname);
SqlDataAdapter dacatname = new SqlDataAdapter(cmdcatname);
cmdcatname.ExecuteNonQuery();
DataSet dscatanme = new DataSet();
dacatname.Fill(dscatanme);
concatname.Close();
List<CascadingDropDownNameValue> catnamedetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtrow in dscatanme.Tables[0].Rows)
{
string CatID = dtrow["txtcatid"].ToString();
string CatName = dtrow["CatName"].ToString();
catnamedetails.Add(new CascadingDropDownNameValue(CatName, CatID));
}
return catnamedetails.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] BindSubCategory(string knownCategoryValues, string category)
{
Int32 CatID;
//string CatID;
StringDictionary subcatdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
CatID = Convert.ToInt32(subcatdetails["CategoryName"]);
//CatID = subcatdetails["CategoryName"];
SqlConnection consubcat = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString);
consubcat.Open();
SqlCommand cmdsubcat = new SqlCommand("select * from HelpDeskSubCat where catid = @catid", consubcat);
cmdsubcat.Parameters.Add("@catid", SqlDbType.Int).Value = CatID;
//cmdsubcat.Parameters.AddWithValue("@txtcatid", CatID);
cmdsubcat.ExecuteNonQuery();
SqlDataAdapter dasubcat = new SqlDataAdapter(cmdsubcat);
DataSet dsstate = new DataSet();
dasubcat.Fill(dsstate);
consubcat.Close();
List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtstaterow in dsstate.Tables[0].Rows)
{
string subcatID = dtstaterow["subcatid"].ToString();
string SubCatname = dtstaterow["subcatname"].ToString();
statedetails.Add(new CascadingDropDownNameValue(SubCatname, subcatID));
}
return statedetails.ToArray();
}
}
I wonder why the error is only appear when deploy that project on the Server. I try to find out the answers form google but no luck. Why different environment made my project error. Please give me an advise to solve this problem, Thanks
1. In WebService add attribute [System.Web.Script.Services.ScriptService()] to class. 2. If you use another asp controls in the same aspx page add in
3. If yet you get error - try ValidateRequest="false" in the tag
Do you publish the web site correctly with VS2010? And make sure the IIS server select the correct version asp.net. And also make sure the ajaxcontroltoolkit.dll is copied to the server.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Sorry I never told you that everything worked fine until Monday 23, the server was down because of blackout. The server can't bootup, so the technician guys reinstalled ws 08 and re-configured IIS but it is not be the same. My app can't run smoothly as I
mentioned above. I don't know why. Right now, my app can't run. There are 2 errors occured one is
AccessFile is not valid and the second is 404 - File or directory not found when retrieved the page that use URL routing. If the application pool enable 32bit to true, my app can run without the error of valid Accessfile. but it still got an error of
URL routing. Can I solve this problem.
sorasak
0 Points
9 Posts
ajax cascadingdropdown Conversion failed method error 500
Apr 29, 2012 02:41 PM|LINK
Hello, I created Ajax cascadingdownload list in my project. It worked fine in my localhost but when deployed it to my university's web server, the method error 500 was shown on page loaded. so the Firebug told me that the error is coming form "Conversion failed when converting the nvarchar value 'BindCategory' to datatype Int." My code is below:
<table cellpadding="2" width="100%"> <tr> <td style="height:25px;"> <asp:Label ID="Label4" runat="server" CssClass="LabelTitle" Text="หมวดคำถาม:"></asp:Label> <asp:DropDownList ID="DDLCatName" runat="server" CssClass="DDLText"></asp:DropDownList> <asp:CascadingDropDown ID="CCCatName" runat="server" Category="CategoryName" TargetControlID="DDLCatName" PromptText="--โปรดเลือกหมวดคำถามหลัก--" LoadingText="Loading Categories.." ServiceMethod="BindCategory" ServicePath="CascadingDropdown.asmx"> </asp:CascadingDropDown> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="DDLCatName" CssClass="failureNotification" ErrorMessage="โปรดเลือกหมวดคำถามหลัก" ></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="height:25px;"> <asp:Label ID="Label5" runat="server" CssClass="LabelTitle" Text="หมวดคำถามย่อย:"></asp:Label> <asp:DropDownList ID="DDLSubCatName" runat="server" CssClass="DDLText"></asp:DropDownList> <asp:CascadingDropDown ID="ccdSubCatName" runat="server" Category="SubCatName" ParentControlID="DDLCatName" TargetControlID="DDLSubCatName" PromptText="--โปรดเลือกหมวดคำถามย่อย--" LoadingText="Loading Sub Category.." ServiceMethod="BindSubCategory" ServicePath="CascadingDropdown.asmx"> </asp:CascadingDropDown> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DDLSubCatName" CssClass="failureNotification" ErrorMessage="โปรดเลือกหมวดคำถามย่อย" ></asp:RequiredFieldValidator> </td> </tr>Webservice Code:
using System.Data; using System.Web.Services; using System.Collections.Generic; using System.Collections.Specialized; using AjaxControlToolkit; using System.Configuration; using System.Data.SqlClient; using System.Web.Script.Services; /// <summary> /// Summary description for CascadingDropdown /// </summary> [ScriptService] [WebService(Namespace = "http://tempuri.org/")] //[WebService(Namespace = "http://www.stou.ac.th/Offices/ore/rere/goto/HelpDeskAdmin/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //[System.Web.Script.Services.ScriptService] //[System.Web.Script.Services.ScriptService()] public class CascadingDropdown : System.Web.Services.WebService { [WebMethod] public CascadingDropDownNameValue[] BindCategory(string knownCategoryValues, string category) { SqlConnection concatname = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString); concatname.Open(); SqlCommand cmdcatname = new SqlCommand("select * from HelpDeskCat where IsActive = 1", concatname); SqlDataAdapter dacatname = new SqlDataAdapter(cmdcatname); cmdcatname.ExecuteNonQuery(); DataSet dscatanme = new DataSet(); dacatname.Fill(dscatanme); concatname.Close(); List<CascadingDropDownNameValue> catnamedetails = new List<CascadingDropDownNameValue>(); foreach (DataRow dtrow in dscatanme.Tables[0].Rows) { string CatID = dtrow["txtcatid"].ToString(); string CatName = dtrow["CatName"].ToString(); catnamedetails.Add(new CascadingDropDownNameValue(CatName, CatID)); } return catnamedetails.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] BindSubCategory(string knownCategoryValues, string category) { Int32 CatID; //string CatID; StringDictionary subcatdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); CatID = Convert.ToInt32(subcatdetails["CategoryName"]); //CatID = subcatdetails["CategoryName"]; SqlConnection consubcat = new SqlConnection(ConfigurationManager.ConnectionStrings["OREConnectionString"].ConnectionString); consubcat.Open(); SqlCommand cmdsubcat = new SqlCommand("select * from HelpDeskSubCat where catid = @catid", consubcat); cmdsubcat.Parameters.Add("@catid", SqlDbType.Int).Value = CatID; //cmdsubcat.Parameters.AddWithValue("@txtcatid", CatID); cmdsubcat.ExecuteNonQuery(); SqlDataAdapter dasubcat = new SqlDataAdapter(cmdsubcat); DataSet dsstate = new DataSet(); dasubcat.Fill(dsstate); consubcat.Close(); List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>(); foreach (DataRow dtstaterow in dsstate.Tables[0].Rows) { string subcatID = dtstaterow["subcatid"].ToString(); string SubCatname = dtstaterow["subcatname"].ToString(); statedetails.Add(new CascadingDropDownNameValue(SubCatname, subcatID)); } return statedetails.ToArray(); } }I wonder why the error is only appear when deploy that project on the Server. I try to find out the answers form google but no luck. Why different environment made my project error. Please give me an advise to solve this problem, Thanks
MethodError500
Shoaib Rashe...
Member
4 Points
3 Posts
Re: ajax cascadingdropdown Conversion failed method error 500
Apr 29, 2012 02:58 PM|LINK
have you installed ajax on iis
sorasak
0 Points
9 Posts
Re: ajax cascadingdropdown Conversion failed method error 500
Apr 29, 2012 09:58 PM|LINK
Thanks for reply. I've uploaded Ajax ControlToolKit in my Bin Directory. Do it need to install into web server?
chetan.sarod...
All-Star
65789 Points
11153 Posts
Re: ajax cascadingdropdown Conversion failed method error 500
Apr 30, 2012 03:14 AM|LINK
Hi,
There are three reasons can cause error 500.
1. In WebService add attribute [System.Web.Script.Services.ScriptService()] to class. 2. If you use another asp controls in the same aspx page add in
3. If yet you get error - try ValidateRequest="false" in the tag
Please check the following link about this error: http://www.benhblog.com/2008/09/method-error-500-and-ajax.html
Please refer to this faq which tells you how to locate the cause. It's usually much easier to find it our in your practical environment.
</div>MethodError500
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: ajax cascadingdropdown Conversion failed method error 500
May 02, 2012 06:39 AM|LINK
Hi,
Do you publish the web site correctly with VS2010? And make sure the IIS server select the correct version asp.net. And also make sure the ajaxcontroltoolkit.dll is copied to the server.
Feedback to us
Develop and promote your apps in Windows Store
sorasak
0 Points
9 Posts
Re: ajax cascadingdropdown Conversion failed method error 500
May 02, 2012 10:15 AM|LINK
Sorry I never told you that everything worked fine until Monday 23, the server was down because of blackout. The server can't bootup, so the technician guys reinstalled ws 08 and re-configured IIS but it is not be the same. My app can't run smoothly as I mentioned above. I don't know why. Right now, my app can't run. There are 2 errors occured one is AccessFile is not valid and the second is 404 - File or directory not found when retrieved the page that use URL routing. If the application pool enable 32bit to true, my app can run without the error of valid Accessfile. but it still got an error of URL routing. Can I solve this problem.
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: ajax cascadingdropdown Conversion failed method error 500
May 03, 2012 01:34 AM|LINK
Hi,
I think this is not ajax problem, maybe IIS or you publish not correctly. Please check again.
Feedback to us
Develop and promote your apps in Windows Store