우리 응용 프로그램은 EF 5 및 C# .net 4.5를 사용하고 있습니다. 우리 응용 프로그램은 하나의 cenral 서버로 전 세계에서 사용되기 때문에 시간 초과로 실행되고 서버에 대한 연결이 끊어지는 문제가 있습니다.엔터티 프레임 워크 연결 손실 처리
현재 SaveChanges() 메소드를 catch하고 사용자가 취소 할 때까지 다시 시도합니다. 코드에서 수행하는 다양한로드에 대해 우리는 무엇을 할 수 있습니까?
편집 : 제안 된 솔루션을 시도했지만 내가 그것을 제대로 작동하지 않습니다
public class MyRetryStrategy : ITransientErrorDetectionStrategy
{
public bool IsTransient(Exception ex)
{
if (ex != null && ex is SqlException)
{
foreach (SqlError error in (ex as SqlException).Errors)
{
switch (error.Number)
{
case 1205:
System.Diagnostics.Debug.WriteLine("SQL Error: Deadlock condition. Retrying...");
return true;
case -2:
System.Diagnostics.Debug.WriteLine("SQL Error: Timeout expired. Retrying...");
return true;
case -1:
System.Diagnostics.Debug.WriteLine("SQL Error: Timeout expired. Retrying...");
return true;
}
}
}
if (ex != null && ex is EntityException)
{
ex = ex.InnerException;
foreach (SqlError error in (ex as SqlException).Errors)
{
switch (error.Number)
{
case 1205:
System.Diagnostics.Debug.WriteLine("SQL Error: Deadlock condition. Retrying...");
return true;
case -2:
System.Diagnostics.Debug.WriteLine("SQL Error: Timeout expired. Retrying...");
return true;
case -1:
System.Diagnostics.Debug.WriteLine("SQL Error: Timeout expired. Retrying...");
return true;
}
}
}
// For all others, do not retry.
return false;
}
}
, 엔티티 프레임 워크는 나에게 EntityExceptions를 던졌습니다 내가 두 번째 코드 경로를 추가 있도록.
실제 사용법 :
RetryPolicy policy = new RetryPolicy<MyRetryStrategy>(5, TimeSpan.FromMilliseconds(1000));
policy.ExecuteAction(()=>_context.ProductStatuses.Include(x => x.Name.Translations).Load());
MyRetryStrategy의 IsTransient 메소드가 호출되지 않습니다, 또한 어떤 시도가 호출되지 않습니다. 나는 전화하기 전에 데이터뱅크를 멈추게했다.
내가 뭘 잘못하고 있니?