Results 1 to 3 of 3

Thread: error after run webservice in url

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2018
    Posts
    25

    Question error after run webservice in url

    hello

    i write a webservice.
    when i run it in localhost it work fine.
    but after upload it in my host, it also work (register data in db). but show a error.

    here is error message:
    Server Error in '/' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
    DOAdverisingModule.AdsModule.context_PostRequestHandlerExecute(Object sender, EventArgs e) +295
    System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
    System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3163.0


    --------------------------------------------------------------
    here is code of webservice
    [WebMethod]
    public void insert_into_test_tbl(string name, int grade)
    {
    con = new SqlConnection(conString);
    SqlCommand cmd = con.CreateCommand();
    SqlTransaction tr;


    string comm = "insert into test_tbl (name, grade) VALUES(N'" +
    name + "', " +
    grade + ") ";

    cmd.CommandText = comm;

    if (con.State == ConnectionState.Closed)
    con.Open();

    tr = con.BeginTransaction();
    cmd.Transaction = tr;
    cmd.ExecuteNonQuery();
    tr.Commit();

    }

    thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: error after run webservice in url

    Please use appropriate formatting tags to aid readability.
    Quote Originally Posted by armm1388 View Post
    hello

    i write a webservice.
    when i run it in localhost it work fine.
    but after upload it in my host, it also work (register data in db). but show a error.

    here is error message:
    Server Error in '/' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [NullReferenceException: Object reference not set to an instance of an object.]
    DOAdverisingModule.AdsModule.context_PostRequestHandlerExecute(Object sender, EventArgs e) +295
    System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
    System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3163.0

    --------------------------------------------------------------
    here is code of webservice
    Code:
            [WebMethod]
            public void insert_into_test_tbl(string name, int grade)
            {
                con = new SqlConnection(conString);
                SqlCommand cmd = con.CreateCommand();
                SqlTransaction tr;
    
    
                string comm = "insert into test_tbl (name, grade) VALUES(N'" +
                    name + "', " +
                    grade + ") ";
    
                cmd.CommandText = comm;
    
                if (con.State == ConnectionState.Closed)
                    con.Open();
    
                tr = con.BeginTransaction();
                cmd.Transaction = tr;
                cmd.ExecuteNonQuery();
                tr.Commit();
    
            }
    thanks

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: error after run webservice in url

    Exactly as the exception states, a NullReferenceException is being thrown on line 295 in DOAdverisingModule.AdsModule.context_PostRequestHandlerExecute. A NullReferenceException occurs when you try to access a member of an object via a variable or other reference that is null. You should spend some time learning how to read an exception stack trace.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width