What causes a Microsoft.Isam.Esent.Interop.EsentOutOfCursorsException

Oct 11, 2012 at 9:32 PM

I have set up some unit tests that test the Esent Database. when they run individually they run fine, but when I run all my unit tests in a single test run I get a "Microsoft.Isam.Esent.Interop.EsentOutOfCursorsException"

Can any one tell me what this is a sign of?

Oct 11, 2012 at 9:43 PM

ESE has finite resources. Are you closing things after you open them?

If you're using the Table class, it's IDisposable. Be sure to Dispose() it when you're done (or use a 'using' statement if appropriate).

You can up the max InstanceParameters.MaxOpenTables if you actually need to. But fixing leaks is a better idea. :)


Oct 11, 2012 at 10:42 PM

Thanks I figured it out just after posting.  I was using Api.TryOpenTable. and not closing the JET_TABLEID after. I have replaced it with the Table wrapper.

using (var table = new Table(currentSession, dbid, "messages", OpenTableGrbit.None))


I have a somewhat related question. This showed up in a piece of code where I get all records from one table and then as I read each record I open another table and get the related records in that table. I have tried the approach of opening and closing the table each time I go through the loop and I have tried opening the table once and repositioning the cursor each time.

Is there any prefered way to do this?  

Oct 11, 2012 at 11:11 PM

Keeping the table open will result in better performance. Opening and closing tables isn't prohibitively expensive, but it's not free either.

You may want to look at the TableEnumerator<T> class to see an example of how it's done. It's an abstract class, and the concrete classes provided are for enuemrating schema. But you can use them as examples.