System.InvalidOperationException: Unexpected connection state. When using a wrapping provider ensure

System.InvalidOperationException: Unexpected connection state. When using a wrapping provider ensure that the StateChange event is implemented on the wrapped DbConnection.

System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.TimeoutException: Timeout in IO operation

开发项目在使用EF6遇到的坑!

1、有时候调试停个一两分钟,然后继续调试可能就会出现这个错误,然后无法连接数据库。

2、其它未知错误也可能会引发该错误。

解决办法:创建一个新的DbContext即可解决

try{

     //你执行的代码。。。。。

}catch(System.InvalidOperationException inverr)

{

    //Creating a new db-context solved the problem.

   //创建一个新的DbContext即可解决

}

 

上一篇:Error during WebSocket handshake: Unexpected response code: 404


下一篇:Uncaught SyntaxError: Unexpected token ')'