Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
819 views
in Technique[技术] by (71.8m points)

entity framework - EF recovery from invalidoperationexception caused by server being down

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 happen before?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...