microsoft / ManagedEsent

MIT License
242 stars 36 forks source link

Termination in progress exception #10

Closed alikilinc closed 5 years ago

alikilinc commented 6 years ago

Hello,

I am using ManagedEsent in my project. I need to do something on different databases in one process. Think a simple ui which has a button which takes a path from user that includes a valid database file (x.edb) and then do the following:

Create an instance ( with the same name in every call) Set some system parameters (circularlog, SystemPath, LogFilePath vs) instance.Init() BeginSession (using instance) AttachDatabase (sample project says that "Redundant Attach calls are safe") OpenDatabase OpenTable BeginTransaction Some delete, insert operations CommitTransaction( with CommitTransactionGrbit.None - I also tried other two options) CloseTable CloseDatabase EndSession Terminate instance ( I tried both JetTerm and JetTerm2 api with different TermGrbit options)

After calling this function 1-4 times successfully, a following call throws EsentTermInProgressException (Termination in progress) at any line of method. (sometimes deleting a row, sometimes closing table, sometimes closing database).

OS: Windows 7 Enterprise 64-bit Using .NET 4.5

Is this a known issue or am i missing something ? Could you please help ? Thank you...

machish commented 6 years ago

@alikilinc , that isn't a great programming model. It will not scale very well. Both Init and Term can do a LOT of disk I/O. You should create a single instance, and attach the database once in your service. Only do the DetachDatabase/Term when you shut the service down.

Each request should Begin a session, do the Open's, Begin/Commit the transaction. (For even greater scale you can re-use the sessions, keeping them around in a pool that you only close when you're shutting the service down.)