1

在Entity Framework中處理網絡錯誤的最佳方法是什麼?每次我有一個可憐的Internet連接到SQL Azure的數據庫,我收到以下錯誤:實體框架:處理錯誤底層提供者無法打開

The underlying provider failed on Open.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

我知道這個錯誤是通過在工作中的互聯網連接的穩定性造成的,所以我並不想修復錯誤,但要妥善處理它給用戶。

我可以使用try catch,但是我將不得不修改每個嘗試使用連接的類的每一行。

一種替代方法是使用存儲庫進行連接並處理錯誤,但需要花費大量時間來重構代碼的每個部分。所以我正在尋找替代品。

Context DB = new Context(); 

List<Persona> lista = new List<Persona>(); 
List<Persona> listaTemporal = new List<Persona>(); 

listaTemporal = DB.Personas.Where(one => one.Activo == true && 
             one.FechaEstadoInicialSAP != null) 
          .ToList(); // it stops here because of the exception 
+0

http://www.asp.net/mvc/overview/getting-started/getting-started-with -ef-using-mvc/connection-resiliency-and-command-interception-with-the-the-entity-framework-in-an-asp-net-mvc-application – yyou

+0

使用'嘗試抓住'塊。 –

回答

相關問題