데이터베이스 서버가 다운되었을 때 데이터베이스 예외를 잡으려고합니다. 우리는 Sybase IAnywhere를 사용합니다.왜 내부 예외를 잡을 수 없습니까?
일반 C# try catch를 사용하여 데이터베이스 예외의 이름을 가져옵니다.
try
{
//code here
}
catch (Exception ex)
{
Logging.Log.logItem(LogType.Exception, "Exception in isDBRunning", "App_Startup::isDBRunning() ", "GetBaseException=" + ex.GetBaseException().ToString() + "\nMessage=" + ex.Message + "\nStackTrace: " + ex.StackTrace + "\nInnerException: " + ex.InnerException);
}
예외 밖으로 인쇄
은 이것이다 :GetBaseException=iAnywhere.Data.SQLAnywhere.SAException: Database server not found
at iAnywhere.Data.SQLAnywhere.SAConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
Message=The underlying provider failed on Open.
StackTrace: at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2[TResult](IEnumerable`1 sequence)
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at Analogic.SystemSoftware.App.isDBRunning() in C:\workspace\SystemSoftware\SystemSoftware\src\startup\App.xaml.cs:line 158
InnerException: iAnywhere.Data.SQLAnywhere.SAException: Database server not found
at iAnywhere.Data.SQLAnywhere.SAConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
그래서 나는 iAnywhere.Data.SQLAnywhere.SAException
내가 처리해야 진짜 예외라고 생각합니다.
try
{
//code here
}
catch (iAnywhere.Data.SQLAnywhere.SAException ex)
{
Logging.Log.logItem(LogType.Exception, "Exception in isDBRunning 1", "App_Startup::isDBRunning() ", "GetBaseException=" + ex.GetBaseException().ToString() + "\nMessage=" + ex.Message + "\nStackTrace: " + ex.StackTrace + "\nInnerException: " + ex.InnerException);
}
catch (Exception ex)
{
Logging.Log.logItem(LogType.Exception, "Exception in isDBRunning", "App_Startup::isDBRunning() ", "GetBaseException=" + ex.GetBaseException().ToString() + "\nMessage=" + ex.Message + "\nStackTrace: " + ex.StackTrace + "\nInnerException: " + ex.InnerException);
}
그러나 iAnywhere.Data.SQLAnywhere.SAException
적발되지 않습니다 : 그럼 난 그것을 위해 캐치를 추가했다. 나는 아직도 Exception
을 잡았다. 왜?
"// 여기에서 코드를 확장 할 수 있습니까?"이 코드는 app.xaml.cs 파일의 158 행 주위에 있습니까? – NotMe
또한 배포 된 코드입니까? – NotMe
"// 여기에 코드"는 검색을 위해 데이터베이스에 연결하는 코드를 의미합니다. 그리고 목적에 따라 DB 서버를 종료했습니다. 그래서 나는 데이터베이스에서 예외를 얻을 것이다. – 5YrsLaterDBA