Results 1 to 9 of 9

Thread: Application Crashes due to error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    323

    Application Crashes due to error

    Hi every one,

    Some times my application crashes. From windows event viewer i copied all details, can anyone please guide me where is the issue in my application.

    Thanks in advance

    Ladak



    Application: PTSConMaster.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.InvalidOperationException
    Stack:
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, Boolean, Boolean, Int32, System.Threading.Tasks.Task ByRef, Boolean, System.Data.SqlClient.SqlDataReader)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, Boolean, System.String, System.Threading.Tasks.TaskCompletionSource`1<System.Object>, Int32, System.Threading.Tasks.Task ByRef, Boolean)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, Boolean, System.String)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(System.Data.CommandBehavior, System.String)
    at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(System.Data.CommandBehavior)
    at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(System.Data.CommandBehavior)
    at System.Data.Common.DbDataAdapter.FillInternal(System.Data.DataSet, System.Data.DataTable[], Int32, Int32, System.String, System.Data.IDbCommand, System.Data.CommandBehavior)
    at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable[], Int32, Int32, System.Data.IDbCommand, System.Data.CommandBehavior)
    at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)
    at Module1.GetLastShiftNumber()
    at TiT.PTS.FuelPointControl.SaveTransaction()
    at TiT.PTS.FuelPointControl.fuelPoint_TransactionFinished(System.Object, TiT.PTS.TransactionEventArgs)
    at TiT.PTS.FuelPoint.OnTransactionFinished(TiT.PTS.TransactionEventArgs)
    at TiT.PTS.PTS.processResponseMessage(Int32, Byte[])
    at TiT.PTS.PTS.sendMessage(Int32, Byte[])
    at TiT.PTS.PTS.RequestExtendedStatus(Int32)
    at TiT.PTS.FuelPoint.GetStatus()
    at TiT.PTS.PTS+_Closure$__1._Lambda$__1()
    at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
    at System.Threading.ThreadHelper.ThreadStart()

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,835

    Re: Application Crashes due to error

    I'm guessing you don't use error handling, or, at least not in this case. Error handling is a good habit to get into

    Looking at the message it appears to be an issue with some kind of SQL\Database processing. I'd start by using error handling in those routines.
    Please remember next time...elections matter!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    323

    Re: Application Crashes due to error

    Thanks TysonLPrice for your reply,

    I already placed Try Catch to handle errors, but still getting this error. Amazing thing is this error appears after 3 days, sometime after 4 days.
    That's why I am confused.

    Ladak

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    323

    Re: Application Crashes due to error

    I just want to know after looking at this error what do you think in which routine/procedure the error exits?

    Ladak

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,835

    Re: Application Crashes due to error

    Here is an error handling routine I use:

    Put this somewhere public:

    Code:
    Public Function GetExceptionInfo(ex As Exception) As String
            Dim Result As String
            Dim hr As Integer = Runtime.InteropServices.Marshal.GetHRForException(ex)
            Result = ex.GetType.ToString & "(0x" & hr.ToString("X8") & "): " & ex.Message & Environment.NewLine & ex.StackTrace & Environment.NewLine
            Dim st As StackTrace = New StackTrace(ex, True)
            For Each sf As StackFrame In st.GetFrames
                If sf.GetFileLineNumber() > 0 Then
                    Result &= "Line:" & sf.GetFileLineNumber() & " Filename: " & IO.Path.GetFileName(sf.GetFileName) & Environment.NewLine
                End If
            Next
            Return Result
        End Function
    And the routine:

    Code:
    Catch ex As Exception
                mErrorMessage = "Error in ExecuteStoredProcedure - Line number: " & GetExceptionInfo(ex)
                MsgBox(mErrorMessage)
                Me.Cursor = Windows.Forms.Cursors.Default
                Exit Sub
            End Try
    It will give you much better diagnostics and the line number where it occurred. It doesn't help much if you don't know where to put it though. If I were in your shoes I'd spend whatever time it took to add it in everywhere - if that is possible. If not, everywhere you call a database.
    Please remember next time...elections matter!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    323

    Re: Application Crashes due to error

    Thanks for the codes. I will put these codes and check.

    Thanks
    Ladak

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Application Crashes due to error

    You don't always get a lot of information about exceptions unless you log them yourself. But there's some information you can glean from this report. The call stack tells you the InvalidOperationException happened this way:

    • The culprit who threw it is SqlCommand.RunExecuteReaderTds(), which is probably something someone else wrote.
    • Walking up the call stack, it looks like the part where your code starts is Module1.GetLastShiftNumber(). It calls DbDataAdapter.Fill(), and that led to the exception.
    • Walking up that call stack helps you understand what the program was doing. The chain of events seems to be: someone called FuelPoint.GetStatus(), it called Pts.RequestExtendedStatus(), that raised an event that is handled by FuelPointControl.fuelPoint_TransactionFinished(), and the reason you called DbDataAdapter.Fill() is that method calls FuelPointControl.SaveTransaction().

    That should help you understand where you need some exception handling to get more information. In particular, the Message property of the exception should tell you what happened.

    Honestly the default Exception.ToString() is generally sufficient: it spits out the message and the stack trace. All you really tend to want to add to that is the name. Here's roughly how I log exceptions:
    Code:
    Sub LogException(ByVal ex As Exception, ByVal extraInfo As String)
        Dim messageBuilder As New System.Text.StringBuilder()
        messageBuilder.AppendLine(String.Format("EXCEPTION {0}:", extraInfo)
        messageBuilder.AppendLine(ex.GetType().Name)
        messageBuilder.AppendLine(ex.ToString())
    
        LogToFile(messageBuilder.ToString())
    End Sub
    In code I want to protect, I use it like this:
    Code:
    Sub LoadCustomers()
        Try
            ' Do some stuff with a database
        Catch ex As Exception
            LogToFile(ex, "[LoadCustomers]")
        End Try
    End Sub
    So my log file would generally look like:
    Code:
    EXCEPTION [LoadCustomers]
    Call Open() before using the connection.
    System.Data.SqlException
    at System.Data....
    ...
    There's a lot of good ideas around logging exceptions experience has taught me, but this is enough to help you get moving.
    Last edited by Sitten Spynne; May 15th, 2017 at 08:38 AM.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  8. #8
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,835

    Re: Application Crashes due to error

    Quote Originally Posted by Sitten Spynne View Post
    For some reason, TysonLPrice's code doesn't list that. I think it's the most important thing.
    Is this what you say is missing from the routine I posted?

    & ex.Message &
    Please remember next time...elections matter!

  9. #9
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Application Crashes due to error

    You're right, it's in there, just buried a little where I didn't notice it. That tends to happen in fairly dense chunks of code with a lot of concatenation. I edited that part of my post out.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

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