简体   繁体   English

EntityException:底层提供程序在Open +内部异常上失败

[英]EntityException: The underlying provider failed on Open + inner exceptions

I apologize in beforehand because I see that a lot of people have already answered this question but still I cannot find the answer I am looking for. 我事先道歉,因为我看到很多人已经回答了这个问题,但我仍然无法找到我想要的答案。

In my solution I got 5 projects where 2 are C# libraries (the Core layer and the Data layer). 在我的解决方案中,我得到了5个项目,其中2个是C#库(Core层和数据层)。 The other 3 are using the Core layer to connect to the data layer and these three are a web-API project, a test winform project and a MVC project. 其他3个使用Core层连接到数据层,这三个是web-API项目,测试winform项目和MVC项目。 I am currently trying out the winform project and that is where the error occurs. 我目前正在尝试winform项目,这就是错误发生的地方。 The API project works fine when connecting to database. 连接到数据库时,API项目工作正常。

As the title suggest I have gotten this common exception in the winform project 正如标题所示,我在winform项目中得到了这个常见的例外

System.Data.DataException: 'An exception occurred while initializing the database. System.Data.DataException:'初始化数据库时发生异常。 See the InnerException for details.' 有关详细信息,请参阅InnerException。

EntityException: The underlying provider failed on Open. EntityException:底层提供程序在Open上失败。

with the following inner exceptions 具有以下内部异常

SqlException: Connection Timeout Expired. SqlException:连接超时已过期。 The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. 尝试使用登录前握手确认时超时时间已过。 This could be because the pre-login handshake failed or the server was unable to respond back in time. 这可能是因为登录前握手失败或服务器无法及时响应。 The duration spent while attempting to connect to this server was - [Pre-Login] initialization=38878; 尝试连接到此服务器所花费的时间是 - [Pre-Login] initialization = 38878; handshake=35; 握手= 35;


Win32Exception: The wait operation times out Win32Exception:等待操作超时

The errors occurs in my Datacontext on Database.Initialize(true); 错误发生在Database.Initialize(true);上的Datacontext中Database.Initialize(true); :

    public class DataContext : DbContext
    {
        public DataContext() : base("HololensRegistreringsskyltar")
        {
            Database.SetInitializer(new DataContextInitializer<DataContext>());
            Database.Initialize(true);
        }
    }

I am also using generic repository pattern with Unit Of Work if that matters (and I am new to it). 如果重要的话,我也使用通用存储库模式和工作单元(我是新手)。

Btw there is only a connection string in the API projects web.config, maybe there should be in the other two "outer" layers too? 顺便说一句,API项目web.config中只有一个连接字符串,也许在其他两个“外部”层中也应该有?

Can anyone tell me how to solve this issue and making it work for all 3 "outer" layers? 谁能告诉我如何解决这个问题并让它适用于所有3个“外层”?

Following cases can cause this exception: 以下情况可能导致此异常:

  • An instance of the SQL Server Database Engine is not running. SQL Server数据库引擎的实例未运行。
  • The SQL Server Browser service is not running. SQL Server Browser服务未运行。
  • The TCP/IP is disabled. TCP / IP已禁用。
  • The server name was typed incorrectly. 服务器名称输入错误。
  • There are network problems. 有网络问题。
  • The TCP/IP port for the Database Engine instance is blocked by a firewall. 防火墙阻止数据库引擎实例的TCP / IP端口。
  • The client and server are not configured to use the same network protocol. 客户端和服务器未配置为使用相同的网络协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM