Scandalous Error: Servermethod "MyMethod" failed

Last post 07-08-2009 5:39 PM by SaraDob. 6 replies.

Sort Posts:

  • Scandalous Error: Servermethod "MyMethod" failed

    06-30-2009, 9:48 AM
    • Member
      91 point Member
    • SaraDob
    • Member since 10-28-2008, 11:04 AM
    • North Carolina
    • Posts 336

     Hi,

    I have going around this error for a while now.Now i realised , there is nothing wrong with my code.can you please help me realise , Why the erros is being thrown?

    I'm calling a javascript function ( on textchanged on text box).In that  javascript, i  have Used Pagemethods to call a server side function(in Code behind) to check ,if the Customer entered is in database or not?

    I have used

    1) Script manager and enabled page methods
    2) I have declared the server side method with 

    <System.Web.Services.WebMethod()> _

    The roor throws up if i enter anything in the textbox: The Server Method"CheckCust" failed. everytime. But few time, it does not. it works correctly. I don't know under what circumstances, the error is throwing up.

     

    I will paste my code below.PLEASE HELP ME in solving this scandulous error.

    Thanks.

     

    '''Server Side function:

    <System.Web.Services.WebMethod()> _

     

    Public Shared Function CheckCustomerInDatabase(ByVal Custname As String) As String

     

     

    Dim MyConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("StrConn"))If Not (Custname Is Nothing OrElse Custname.Length = 0) Then

     

    If MyConn.State = ConnectionState.Closed Then

    MyConn.Open()

     

     

    End If

     

    If MyConn.State = ConnectionState.Open Then

     

    Try

     

    Dim StrCheckCustomer As String

    StrCheckCustomer =

     

     

     

    String.Format("Select CompanyName From Customers where Companyname='{0}'", Custname)Dim CmdCheckCustomer As SqlCommand = New SqlCommand(StrCheckCustomer, MyConn)Dim CustExist As String = Convert.ToString(CmdCheckCustomer.ExecuteScalar())If CustExist Is String.Empty Then

     

     

    Return ("This Customer does not exist in database.To add this Customer,Click on the Icon next the textbox and add customer into Database and then choose it :" & Custname)Else

     

    Return Nothing

     

    End If

     

     

    Catch ex As SqlExceptionReturn "error"

     

    Finally

    MyConn.Close()

     

    End Try

     

     

    End If

     

    End If

     

     

    End Function

    ===Javascript

    function

    {

     

     

    CheckCustomerTextBox=document.getElementById(id);

    CheckCustomer=CheckCustomerTextBox.value;

    PageMethods.CheckCustomerInDatabase(CheckCustomer,CallSuccess,CallFailed);

    }

     

     

    {

     

     

    {

    alert(result);

     

    }

    }

    CheckCustInDB(id)var CheckCustomerTextBox;var CheckCustomer;function CallSuccess(result)if(result!=null)

    function

    {

    alert(error.get_message());

    }

    CallFailed(error)

     }

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">

     

    </asp:ScriptManager>

  • Re: Scandalous Error: Servermethod "MyMethod" failed

    06-30-2009, 12:10 PM
    • Contributor
      2,367 point Contributor
    • akhhttar
    • Member since 02-14-2007, 8:17 AM
    • Pakistan - Lahore
    • Posts 352

    Hi,

    Did you try to debug Javascript and Server Side code? Where does this errror actually happen? Did request reach at server or not?

    Thanks

    Muhammad Akhtar Shiekh

    Lets resolve the problem together.

    Please remember to mark the appropriate replies as answer after your question is solved, thanks

    My Blog
  • Re: Scandalous Error: Servermethod "MyMethod" failed

    07-02-2009, 11:53 AM
    • Member
      91 point Member
    • SaraDob
    • Member since 10-28-2008, 11:04 AM
    • North Carolina
    • Posts 336

     Thanks for your reply..(Sorry for the delay in my reply).

    The javascript is being called.I think i get the error when the page methods are being called.

     

    Anything else?

  • Re: Scandalous Error: Servermethod "MyMethod" failed

    07-02-2009, 1:15 PM
    • Contributor
      5,082 point Contributor
    • mrmercury
    • Member since 04-04-2006, 6:26 PM
    • Mexico City, Mexico
    • Posts 739

    It looks like the problem is in the CheckCustomerInDatabase method since it seems to work part of the time, and since you as the programmer are responsible for what goes wrong with your WebService you should always log the exceptions that get thrown inside the WebMethod, this way you’ll be able to see what’s going on.

    If this post helped you please remember to set it as Answer so it can help others.
  • Re: Scandalous Error: Servermethod "MyMethod" failed

    07-02-2009, 5:03 PM
    • Member
      91 point Member
    • SaraDob
    • Member since 10-28-2008, 11:04 AM
    • North Carolina
    • Posts 336

     Since i'm anewbie, i'm trying to understand these concepts.Can ypu please let me know how to catch this exceptions?

    Please

  • Re: Scandalous Error: Servermethod "MyMethod" failed

    07-02-2009, 7:26 PM
    Answer
    • Contributor
      5,082 point Contributor
    • mrmercury
    • Member since 04-04-2006, 6:26 PM
    • Mexico City, Mexico
    • Posts 739

    You are already catching them since you are using the try-catch blocks, now you need to send them to the log in the catch block, there are several way s of doing this: you could use your own log system, or you could use Window’s event logs, this way the system administrator will be able to check the logs in the case of a problem with your WebService and use the information to solve the issue, for this you can use the System.Diagnostics.EventLog class,  it’s really easy to use it check the .NET documentation for an example,  you can use the Window’s Event Viewer to examine the logs, note that you should be able to create new logs in your development machine, but you’ll need to register the application with the Event Viewer to be able to create logs in the server using theEventLog’s  CreateEventSource() method.

    If this post helped you please remember to set it as Answer so it can help others.
  • Urgent: Scandalous Error: Servermethod "MyMethod" failed

    07-08-2009, 5:39 PM
    • Member
      91 point Member
    • SaraDob
    • Member since 10-28-2008, 11:04 AM
    • North Carolina
    • Posts 336

    Sorry for getting Back this late.Was caught with other Issues.

    Well, thanks for Suggesting me to look into eventLog mrmercury.

    I checked everything on Code Side.Everything is working fine.
    I got to See the Application Log in the event Viewer.Here is what i found:


    I'm using Master Pages. Page B.aspx has the textbox control,Javascript and web method in it.

    I have A.aspx, which has some information.After the User Selects this info, i Server.transfer to B.aspx.

    So when the webmethod on B.aspx is trying to Display the message, it is seraching for A.aspx.
    I don't know y this is happening.


    Please help me to correct this.

Page 1 of 1 (7 items)