Quantcast
Channel: ESENT Managed Interface
Viewing all 496 articles
Browse latest View live

New Post: How to set CacheSizeMax after the constructor of PersistentDictionary has been run?

$
0
0
Here is my scenario:
I have a code that uses PersistentDictionary() which will cause the database cache to be over 3GB.
After that code is run, I want to set CacheSizeMax to 100MB to force it to dump majority of the cached data.
I do NOT want to dispose the PersistentDictionary() object, because I am going to use this same object 10 minutes later.

The only way I can see about using CacheSizeMax is from the constructor like the following (refer to this related thread https://managedesent.codeplex.com/discussions/644171 for details).
Is there a way to set it after using the dictionary without disposing it?
    DatabaseConfig databaseConfig = new DatabaseConfig()
    {
        CacheSizeMax = 3 * 1024 * 1024 * 1024 / 8192;  // That is 3GB
    };

    var dictionary = new PersistentDictionary<TKey, string>("myfile", databaseConfig);
    // Use dictionary now...
    // How to set CacheSizeMax to 100MB after using the dictionary without disposing it?
Thanks.

New Post: How to set CacheSizeMax after the constructor of PersistentDictionary has been run?

$
0
0
Try using the Database property.
        /// <summary>
        /// Gets the Database object associated with the dictionary.
        /// Database can be used to control runtime parameters affecting the dictionary's backing database (e.g. database cache size).
        /// See <see cref="DatabaseConfig"/>.
        /// </summary>
        /// <value>
        /// The Database object associated with the dictionary.
        /// Database can be used to control runtime parameters affecting the dictionary's backing database (e.g. database cache size).
        /// See <see cref="DatabaseConfig"/>.
        /// </value>
        public Database Database

New Post: Data not beeing saved in edb file

$
0
0
Hi,

Maybe I'm beeing dump or missing some step, but I've created a VB.NET program to create a database, create a table, create two columns (parameter and value). I also tried to save two values ("par1" and "val1"), but when I close my program and try only to read, no to write, I got an error: "Currency not a record". I've tried to use the Esedatabase view and I can see that my table is created but is empty. This is my code:
    Public strArquivoDB As String = fCaminhoDatabase() & "clt.db" 'Nome do arquivo de Database
    Private jetINSTANCE As JET_INSTANCE
    Public jetSESID As JET_SESID
    Public jetDBID As JET_DBID
    Private jetHANDLE As JET_HANDLE
    Private jetTABLEID As JET_TABLEID
    Private jetCOLUMNDEF As JET_COLUMNDEF = New JET_COLUMNDEF()
    Private jetCOLUMNID As JET_COLUMNID

    Public Function fVerificaDBExiste(ByVal strCaminho As String) As Boolean
        'Usada para verificar se o arquivo de DB existe
        Return File.Exists(strCaminho)
    End Function
    Public Function fCriaArquivoDB(ByVal strCaminhoArquivoDB As String, ByVal esentSession As JET_SESID, ByVal esentDBID As JET_DBID) As Boolean
        'Usada para criar arquivo de database
        Try
            If Not (Directory.Exists(fCaminhoDatabase())) Then
                Try
                    Directory.CreateDirectory(fCaminhoDatabase())
                Catch ex As Exception
                    Return False
                    Exit Function
                End Try
            End If
            Api.JetCreateDatabase(esentSession, strCaminhoArquivoDB, Nothing, esentDBID, CreateDatabaseGrbit.None)
            Return True
        Catch e As Exception
            Return False
        End Try
    End Function
    Public Function fCaminhoDatabase() As String
        'Usada para retornar o caminho completo do arquivo de DB
        Return System.AppDomain.CurrentDomain.BaseDirectory() & "Database\"
    End Function
    Public Function fInicializaVariaveisDatabase() As Boolean
        'Usada para inicializar as variaveis de tratamento ESENT e carregar o Database
        Try
            ' Initialize ESENT. Setting JET_param.CircularLog to 1 means ESENT will automatically
            ' delete unneeded logfiles. JetInit will inspect the logfiles to see if the last
            ' shutdown was clean. If it wasn't (e.g. the application crashed) recovery will be
            ' run automatically bringing the database to a consistent state.
            Api.JetCreateInstance(jetINSTANCE, "InstanciaArquivoDB")
            Api.JetSetSystemParameter(jetINSTANCE, JET_SESID.Nil, JET_param.CircularLog, 1, Nothing)
            Api.JetSetSystemParameter(jetINSTANCE, JET_SESID.Nil, JET_param.LogFilePath, 0, fCaminhoDatabase())
            Api.JetSetSystemParameter(jetINSTANCE, JET_SESID.Nil, JET_param.SystemPath, 0, fCaminhoDatabase())
            Api.JetSetSystemParameter(jetINSTANCE, JET_SESID.Nil, JET_param.TempPath, 0, fCaminhoDatabase())
            Api.JetSetSystemParameter(jetINSTANCE, JET_SESID.Nil, JET_param.BaseName, 0, "clt")
            Api.JetInit(jetINSTANCE)
            Api.JetBeginSession(jetINSTANCE, jetSESID, Nothing, Nothing)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Function fFinalizaDatabase() As Boolean
        'Usada para finalizar a sessao de acesso ao ESENT DB
        Try
            Api.JetCloseDatabase(jetSESID, jetDBID, CloseDatabaseGrbit.None)
            Api.JetEndSession(jetSESID, EndSessionGrbit.None)
            Api.JetTerm(jetINSTANCE)
            Return True
        Catch
            Return False
        End Try
    End Function
    Public Function fAbreDatabase() As Boolean
        'Usada para abrir arquivo database
        Try
            Api.JetAttachDatabase(jetSESID, strArquivoDB, AttachDatabaseGrbit.None)
            Api.JetOpenDatabase(jetSESID, strArquivoDB, Nothing, jetDBID, OpenDatabaseGrbit.Exclusive)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Function fCriaEstruturaDatabase() As Boolean
        'Usada para criar estrutura de tabelas
        Try
            Api.JetBeginTransaction(jetSESID)
            Api.JetCreateTable(jetSESID, jetDBID, "Parametros", 0, 100, jetTABLEID)
            jetCOLUMNDEF.coltyp = JET_coltyp.Text
            jetCOLUMNDEF.cp = JET_CP.ASCII
            Api.JetAddColumn(jetSESID, jetTABLEID, "Parametro", jetCOLUMNDEF, Nothing, 0, jetCOLUMNID)
            Api.JetAddColumn(jetSESID, jetTABLEID, "Valor", jetCOLUMNDEF, Nothing, 0, jetCOLUMNID)
            Api.JetCommitTransaction(jetSESID, CommitTransactionGrbit.None)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Function fInsereParametro(ByVal strParametro As String, ByVal strValor As String) As Boolean
        Try
            'Dim jTABLE As New Table(jetSESID, jetDBID, "Parametros", OpenTableGrbit.None)
            Dim jTABLE As JET_TABLEID
            Api.JetBeginTransaction(jetSESID)
            Api.OpenTable(jetSESID, jetDBID, "Parametros", OpenTableGrbit.None, jTABLE)
            Api.JetPrepareUpdate(jetSESID, jTABLE, JET_prep.Insert)
            Dim jCOLUMNIDS As IDictionary(Of String, JET_COLUMNID) = Api.GetColumnDictionary(jetSESID, jTABLE)
            Dim ColunaParametro As JET_COLUMNID = jCOLUMNIDS("Parametro")
            Dim ColunaValor As JET_COLUMNID = jCOLUMNIDS("Valor")
            Api.SetColumn(jetSESID, jTABLE, ColunaParametro, strParametro, Encoding.Unicode)
            Api.SetColumn(jetSESID, jTABLE, ColunaValor, strValor, Encoding.Unicode)
            Api.JetUpdate(jetSESID, jTABLE)
            Api.JetCommitTransaction(jetSESID, CommitTransactionGrbit.WaitLastLevel0Commit)
            Api.JetCloseTable(jetSESID, jTABLE)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Function fLeParametros() As String
        Try
            Dim jTABLE As JET_TABLEID
            Api.JetBeginTransaction(jetSESID)
            Api.OpenTable(jetSESID, jetDBID, "Parametros", OpenTableGrbit.None, jTABLE)
            Dim jCOLUMNIDS As IDictionary(Of String, JET_COLUMNID) = Api.GetColumnDictionary(jetSESID, jTABLE)
            Dim ColunaParametro As JET_COLUMNID = jCOLUMNIDS("Parametro")
            Dim ColunaValor As JET_COLUMNID = jCOLUMNIDS("Valor")
            Api.TryMoveFirst(jetSESID, jTABLE)
            Dim buffer As String = String.Empty
            Do
                buffer = buffer & "Parametro: " & Api.RetrieveColumnAsString(jetSESID, jTABLE, ColunaParametro)
                buffer = buffer & " | Valor: " & Api.RetrieveColumnAsString(jetSESID, jTABLE, ColunaValor) & vbCrLf
            Loop While Api.TryMoveNext(jetSESID, jTABLE)
            Api.JetCloseTable(jetSESID, jTABLE)
            Return buffer
        Catch ex As Exception
            Return False
        End Try
    End Function
I am using a Textbox to write all information:
TextBox1.Text = "Inicializacao: " & fInicializaVariaveisDatabase().ToString()
        If fVerificaDBExiste(strArquivoDB) Then
            TextBox1.Text = TextBox1.Text & vbCrLf & "Arquivo existe: " & fVerificaDBExiste(strArquivoDB).ToString()
        Else
            TextBox1.Text = TextBox1.Text & vbCrLf & "Arquivo existe: " & fVerificaDBExiste(strArquivoDB).ToString()
            TextBox1.Text = TextBox1.Text & vbCrLf & "Criacao arquivo: " & fCriaArquivoDB(strArquivoDB, jetSESID, jetDBID).ToString()
        End If
        TextBox1.Text = TextBox1.Text & vbCrLf & "Abrir arquivo: " & fAbreDatabase().ToString()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Cria estrutura: " & fCriaEstruturaDatabase().ToString()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Insere parametro 1: " & fInsereParametro("Par1", "Vlr1").ToString()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Insere parametro 2: " & fInsereParametro("Par2", "Vlr2").ToString()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Insere parametro 3: " & fInsereParametro("Par3", "Vlr4").ToString()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Insere parametro 4: " & fInsereParametro("Par4", "Vlr3").ToString()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Ler Parametros: " & fLeParametros()
        TextBox1.Text = TextBox1.Text & vbCrLf & "Finalizacao: " & fFinalizaDatabase().ToString()
Regards

Created Unassigned: Open PersistentDictionary using a different value type [13850]

$
0
0
I have been using PersistentDictionary in a windows service with a custom, private type for the value. This has worked well, however I wanted to read the PersistentDictionary files with a separate utility for debugging purposes (while the service is off), however I realized that PersistentDictionary does a validation of the type and will throw if you do not have the exact same .NET type used to create it. Therefore I cannot read these files with any other program than the one that created them (types are internal or private and the assembly is signed). Would it be possible to add the capability to allow a different but compatible type to be used?

New Post: The database page size does not match the engine, trying to open Groove Music Database

$
0
0
I'm currently trying to open the Groove Music Database to read from there the my playlists.

But when I try to JetAttachDatabase I get the follwoing error:

The database page size does not match the engine

The ESEDatabaseView Application can open the database, so the file is not invalid.

I tried to set the DatabasePageSize using follwoing method before the new Instance() constructor

SetIntegerParameter(Esnet.JET_INSTANCE.Nil, Esnet.JET_param.DatabasePageSize, 8192)
private void SetIntegerParameter(Esnet.JET_INSTANCE inst, Esnet.JET_param param, int value)
{
        Esnet.Api.JetSetSystemParameter(inst, Esnet.JET_SESID.Nil, param, value, null);
}

But I got the same error for 8192 16384, and 32768 always the same error, for 2048 I got a invalid parameter error.

Does someone know how to figure out the page size by the database file? Or how to debug the file?

I uploaded my GrooveDatabase if someone wants to try...

https://1drv.ms/u/s!AkY5QCCnUjHghv4ymD8r5EybhzlePg

Thanks you for help :)

EDIT:

I used the advice in this answer
http://stackoverflow.com/questions/5031633/esent-database-engine-limited-to-specific-page-sizes

and set instance.Parameters.Recovery=false;

This way I figured out that the size seem to be 8192, since when callling it with 4096 I still get the The database page size does not match the engine. But with 8192 I get the error Database was not shutdown cleanly. Recovery must first be run to properly complete database operations for the previous shutdown.

But I still don't know how to open the database, since I still get the Database was not shutdown cleanly and setting Recovery=true results in the The database page size does not match the engine again.

(The other thread also does not say how the error got finally fixed)

New Post: The database page size does not match the engine, trying to open Groove Music Database

$
0
0
You may have some leftover log files messing things up. Another person had a similar question with a different database: http://stackoverflow.com/questions/38312774/esent-always-throws-esentpagesizemismatchexception-when-trying-to-open-ie-10-11/

You will need to turn Log File Recovery back on in order to replay the log files to get a cleanly-shutdown database. That's what Groove would be doing.
By disabling recovery, you are telling the database engine to ignore any log files on disk. In other words, your LogFileDirectory and LogFileSize parameters are just being ignored at that point.
If you had Log File Recovery enabled, and started the engine with 'bad' parameters, then those log files may be getting in the way. If you are able to identify which log files were accidentally created, move them to a different location (and then later delete them).

Does that help? Or are you still experiencing difficulties?

-martin

New Post: The database page size does not match the engine, trying to open Groove Music Database

$
0
0
Thank you for your help,

In my Edit I turned Recovery on again, that helped me but,

It turned out that my problem was following:

To prevent my application from destroying the groove database as first step I copy all Files of the Database to a new Temp folder and only Open this copy (I only want to read data and the database is only 12 MB).
Now what I did not know is that just copying the groove database folder to another location does not work, it seems to me the edb database does not work with relative file references, but with direct ones. (correct me if I'm wrong)

This resulted that when I opened the copied edb:

The .edb in my temp still was pointing on the log files at the source location.
So since the log files and the db where at differnet localtions the Esnet Engine correctly told me my database was invalid.
Ironically Trying to open the copied edb (with Recovery=true) also resulting in corrupting the original groove database (or its logs)
Luckyly Groove is so smart to dedect a corrupted database and in this case delete the corrupted database and recover the cache again from the server (I only lost a minor local playlist)

My original Problem is solved, but what still would be nice to know how to copy a edb database correctly?

New Post: The database page size does not match the engine, trying to open Groove Music Database

$
0
0
It's actually the other way. :) The log files point to the full path of the .edb file. When you call JetInit, that initiates log recovery, and will look at the original location (not in your temp directory). That is what will replay the log transactions and make the .edb file in to a 'Clean' shutdown state. That's all done before JetAttachDatabase/JetOpendDatabase.

By copying to a temp location first, you'll need to specify the JET_paramAlternateDatabaseRecoveryPath prior to JetInit, or use the JET_RSTMAP functionality of JetInit3 (I may have these names slightly wrong -- it's off the top of my head :).

Does that help?

Also if you're curious, you can use esentutl -mh foo.edb to look at the header information of the database and see what paths are in there, or esentutl -ml foo.log to see which databases were attached to that transaction log stream, or esentutl -mk foo.chk to dump the checkpoint file (an optimization so that not all log files in a directory are examined every time JetInit is called).

-martin

New Post: The database page size does not match the engine, trying to open Groove Music Database

$
0
0
Thank you very much, that solved my problem :)

Greetings Michael

New Post: Unable to find an entrypoint...

$
0
0
Is this project compatible with Windows 10? I have worked with this back on the windows 7 days without issue but now that I am on windows 10 I am getting the following error. Am I missing something? I created a new project did a nuget reference of the managed esent package
package id="ManagedEsent" version="1.9.4" targetFramework="net461" and attempted to create an instance. I am receiving the error below.
 using (var instance = new Instance("createdatabasetest"))
 {}
Result StackTrace:
at Microsoft.Isam.Esent.Interop.Implementation.NativeMethods.JetCreateInstance(IntPtr& instance, String szInstanceName)
at Microsoft.Isam.Esent.Interop.Implementation.JetApi.JetCreateInstance(JET_INSTANCE& instance, String name) in c:\codeplex\EsentInterop\JetApi.cs:line 124
at Microsoft.Isam.Esent.Interop.Implementation.JetApi.GetVersionFromEsent() in c:\codeplex\EsentInterop\Esent\EsentJetApi.cs:line 124
at Microsoft.Isam.Esent.Interop.Implementation.JetApi.DetermineCapabilities() in c:\codeplex\EsentInterop\Esent\EsentJetApi.cs:line 53
at Microsoft.Isam.Esent.Interop.Implementation.JetApi..ctor() in c:\codeplex\EsentInterop\JetApi.cs:line 95
at Microsoft.Isam.Esent.Interop.Api..cctor() in c:\codeplex\EsentInterop\Api.cs:line 69
--- End of inner exception stack trace ---
at Microsoft.Isam.Esent.Interop.Api.JetCreateInstance2(JET_INSTANCE& instance, String name, String displayName, CreateInstanceGrbit grbit)
at Microsoft.Isam.Esent.Interop.Instance..ctor(String name, String displayName, TermGrbit termGrbit) in c:\codeplex\EsentInterop\Instance.cs:line 117
at Microsoft.Isam.Esent.Interop.Instance..ctor(String name) in c:\codeplex\EsentInterop\Instance.cs:line 53
at EsentTests.TestHelper.CreateDatabase(String storeName, String path) in C:\Dev\Git\Repos\Akka.Persistence.Esent\Esent.Tests\TestHelper.cs:line 43
at EsentTests.TestHelper.CreateDatabase(String storeName) in C:\Dev\Git\Repos\Akka.Persistence.Esent\Esent.Tests\TestHelper.cs:line 24
at Esent.Tests.EsentCreation.DoesStoreExistReturnsFalse() in C:\Dev\Git\Repos\Akka.Persistence.Esent\Esent.Tests\EsentCreation.cs:line 16
Result Message:
Test method Esent.Tests.EsentCreation.DoesStoreExistReturnsFalse threw exception:
System.TypeInitializationException: The type initializer for 'Microsoft.Isam.Esent.Interop.Api' threw an exception. ---> System.EntryPointNotFoundException: Unable to find an entry point named 'JetCreateInstance' in DLL 'esent.dll'.

New Post: Unable to find an entrypoint...

$
0
0
I am using this project on Windows 10 successfully. I just updated my test application to target .Net 4.6.1 but still am not facing any issues.

What version of Windows 10 are you running? Any chance you can take a dump at this point and put it on OneDrive (or something like that)? I'd be happy to take a look for you.

~ Michael

Commented Unassigned: Open PersistentDictionary using a different value type [13850]

$
0
0
I have been using PersistentDictionary in a windows service with a custom, private type for the value. This has worked well, however I wanted to read the PersistentDictionary files with a separate utility for debugging purposes (while the service is off), however I realized that PersistentDictionary does a validation of the type and will throw if you do not have the exact same .NET type used to create it. Therefore I cannot read these files with any other program than the one that created them (types are internal or private and the assembly is signed). Would it be possible to add the capability to allow a different but compatible type to be used?
Comments: PersistentDictionary, under the covers, creates an ESENT database; so if you want access to the database outside the constraints of PersistentDictionary, you can switch to using the ManagedEsent APIs to read it. I would strongly recommend against doing any writes to the database as you might mess up PersistentDictionary's schema, but you should be able to read it with no problems. ~ Michael

Commented Unassigned: Open PersistentDictionary using a different value type [13850]

$
0
0
I have been using PersistentDictionary in a windows service with a custom, private type for the value. This has worked well, however I wanted to read the PersistentDictionary files with a separate utility for debugging purposes (while the service is off), however I realized that PersistentDictionary does a validation of the type and will throw if you do not have the exact same .NET type used to create it. Therefore I cannot read these files with any other program than the one that created them (types are internal or private and the assembly is signed). Would it be possible to add the capability to allow a different but compatible type to be used?
Comments: Right. I could do that but it would require a bit more understanding about the raw ESENT APIs and how PersistentDictionary uses them on my part. I think my starting point would be to fork the project, modify the Collections project to remove the type check in PersistentDictionary.CheckDatabaseMetaData, and see if that works.

New Post: Unable to find an entrypoint...

$
0
0
Thanks for the help. I went back to the start and re-created my project as an empty project with just the 1 line to create an instance and got it to work. I continued recreating the project 1 step at a time to see if I can isolate what it was that caused it, but so far I am back to where I was and it is now working. So its good it's working, but bad I did not know what broke it before.
Anyway thanks for the reassurance that it does work.
Noel

New Post: Unable to find an entrypoint...

$
0
0
That sounds peculiar.
The 32-bit and 64-bit DLLs should both have the same exports, so that's not likely to be a problem.
esent.interop.dll doesn't always look for the esent.dll in system32. If there is an esent.dll in your local directory it could pick that one up instead. Or some other random one on the path. Maybe your old project had a rogue copy of the DLL?
I'm just guessing though. It's rather curious.

-martin

New Post: Unable to find an entrypoint...

$
0
0
That was my theory too. I was hoping a dump could confirm where esent.dll was getting loaded from as that's the only thing that comes to mind that could cause an issue like this. Nanderto - if you run into this again, please check where esent.dll is getting loaded from or take a dump and let me know so I can dig into it.

~ Michael

New Post: What to do if JetRollback fails?

$
0
0
I apologize for not responding earlier. Thanks for the reply / confirmation. Slightly amusingly, the way that the application is using its instance, a process exit and restart is probably the only meaningful way of dealing with it (after initialization, there's no clean way of dealing with the instance becoming offline temporarily). I'll have to make a note to handle this better in the future.

New Post: Data not beeing saved in edb file

$
0
0
There is one issue with your code, which is preventing it from running fully (and saving the data into the database). In fInsereParametro, you need to commit the transaction using either CommitTransactionGrbit.None or CommitTransactionGrbit.LazyFlush. The CommitTransactionGrbit.WaitLastLevel0Commit that you are using is meant to be used outside of open transactions in order to flush all transactions that have been committed but not yet flushed.

There is another issue which will prevent you from getting useful data out of it. You are mixing ASCII and Unicode encodings. In fCriaEstruturaDatabase you are setting up the column with JET_CP.ASCII, but in fInsereParametro you are inserting data with Encoding.Unicode, and in fLeParametros you are calling Api.RetrieveColumnAsString without specifying the Encoding, which will default to Encoding.Unicode. I would suggest just updating the columns to be JET_CP.Unicode.

Created Unassigned: Possible wrong CodeDoc [13851]

$
0
0
Description of Cursor.AcceptChanges() reads as "Discards the changes made to..."

If assigning something to cursor.Record["mycol"] The "EsentNoCurrentRecordException" gives as additional Information:
"Currency not on a record" however it should be "Currently not on a record"

Commented Unassigned: PersistentBlob and "Not supported for SetColumn" [13855]

$
0
0
When creating a PersistentDictionary with a struct as value with a PersistentBlob as field "Not supported for SetColumn" is thrown.

Is this behavior by design?
Comments: Sorry for mistake in prev post, should be: Thanks. No I am trying to do this: struct Foo { int a; } struct Bar { int a; PersistentBlob b; } var myDictionary = new PersistentDictionary<Foo, Bar>();
Viewing all 496 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>