こんにちは、私は開発中のアプリケーションでいくつかの統合テストを行っています。問題の原因となる特定の要素は、Oracleデータベースに問い合わせるバックグラウンド・ワーカーの呼び出しです。クエリでエラーが発生した場合は、例外の詳細をコールスタックをアプリケーションレベルに浸透させ、その時点で適切なユーザー互換のメッセージを提供します。 、のBackgroundWorkerのDoWorkサブにおけるバックグラウンドワーカーで処理されない例外
System.Reflection.TargetInvocationException was unhandled
Message: An unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an
invocation.
:
Oracle.DataAccess.Client.OracleException ORA-00907: missing right parenthesis
残念ながら、コードは次の例外を生成する:サンプルテストに構文エラーがOraEx例外をもたらす基礎となるSQLであります私の信念にもかかわらず、私は例外を正しく処理しています。私がここで何か根本的なものを見逃していることはかなり明白です。誰かが解決策を提案できますか?ここアドバンス ポールJ.における
おかげ
は、バックグラウンドワーカーへの呼び出しを行うコードです:
Private Sub EventSearch(ByVal mySQL As String)
Const procName As String = "EventSearch"
Try
_eventMngr = New ScadaEventManager(_CurrentDB, _userName, _myPwd)
_eventMngr.SQL = mySQL
'Set the flag and stop query tool status accordingly
_Stopped = False
uxStopQueryTool.Enabled = True
'activate the timer object to ensure that the execute query menu
'and tool remain disabled until all background processing is complete
uxBackWorkTimer.Enabled = True
_logger.SendLog(Me.Name & "." & procName & " - Scanning for data.", NLog.LogLevel.Trace)
ReviseStatus(2, "Scanning for data. Please wait...", Color.Black, True, True)
'Force the thread to sleep for half a second so the user can see the scanning state taking place
Threading.Thread.Sleep(500)
'Launch the background worker to retrieve the required data from the database
uxBWScan.RunWorkerAsync(_eventMngr)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, My.Application.Info.ProductName)
_logger.SendLog(ex.Message & ". Thrown in module " & Me.Name.ToString & "." & procName, NLog.LogLevel.Error, ex)
Call ResetStatus()
Finally
End Try
End Sub
そしてここでは、バックグラウンドワーカーによって実行されるコードです:
Private Sub uxBWScan_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles uxBWScan.DoWork
Const procName As String = "uxBWScan_DoWork"
Try
e.Argument.CountRecords(_queryTypeID)
e.Result = e.Argument.RecordCount
Catch NullEx As NullReferenceException
_logger.SendLog(NullEx.Message & ". Thrown in module " & Me.Name.ToString & "." & procName, NLog.LogLevel.Error, NullEx)
Throw
Catch OraEx As OracleException
_logger.SendLog(OraEx.Message & ". Thrown in module " & Me.Name.ToString & "." & procName, NLog.LogLevel.Error, OraEx)
Throw
Finally
End Try
End Sub
エラーを生成する低レベルのコードは次のとおりです。
Public Sub CountRecords(ByVal queryType As Integer)
_myDataset = New DataSet
Try
_myDataset = _myScadaEventDB.CountRecords(_sqlText)
If _myDataset.Tables(0).Rows.Count > 0 Then
If queryType = Enums.QueryType.General Or queryType = Enums.QueryType.KeyPerformanceIndicators Or queryType = Enums.QueryType.TelecontroAnalysis Then
_recordCount = _myDataset.Tables(0).Rows(0).Item("RecordCount")
Else
'The query is grouped therefore count the number of records in the table
_recordCount = _myDataset.Tables(0).Rows.Count
End If
Else
_recordCount = 0
End If
Catch ex As Exception
Throw
Finally
End Try
End Sub
詳細を表示するには、内部例外をチェックしてください。 – N0Alias
イベント引数に 'CountRecords'を呼び出すと、それは早期バインドか遅いバインドですか? 'e.Argument'の型は何ですか?私は、これが遅れてバインドされた呼び出しである可能性があります。したがって、例外は 'TargetInvocationException'でラップされています。上記のコメントに従って、 'TargetInvocationException'の' InnerException'を見て、あなたが期待していたものかどうかを調べることができます。 – Craig
@Craig:延期された呼び出しです。 [** DoWorkEventArgs.Argument'プロパティ**](https://msdn.microsoft.com/en-us/library/system.componentmodel.doworkeventargs.argument(v = vs.110).aspx)は、オブジェクト '。 –