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

使用'尝试抓住'块。 –

回答

相关问题