开发者

EF recovery from invalidoperationexception caused by server being down

开发者 https://www.devze.com 2022-12-30 14:59 出处:网络
I had a windows service relying on EF, and it was running fine until the server went down.The problem was after the server went up again, it didn\'t fix itself and still threw the error:

I had a windows service relying on EF, and it was running fine until the server went down. The problem was after the server went up again, it didn't fix itself and still threw the error:

INTERNAL ERROR: Execution of the command requires an open and available connection. The connection's current state is broken.

Not being very proficient in EF I'm not aware of how I could recover from such a scenario, and why it occurred in the first place? Anyone had this happ开发者_JAVA技巧en before?


What is the lifetime of your ObjectContext? If you are using a single ObjectContext for the lifetime of your service that would cause problems like this. You should instead scope the ObjectContext lifetime down to a smaller window of time, creating a new one for each unit of work.


Solution described here worked for me, modify the connection timeout in your connection string

FROM server='MySQLServer'';Integrated Security=true;Initial Catalog='EVConfiguration';Connection Timeout=100 TO server='MySQLServer';Integrated Security=true;Initial Catalog='EVConfiguration';Connection Timeout=0

0

精彩评论

暂无评论...
验证码 换一张
取 消