.net.net-coreravendb4

RavenDB Client dies in session.Store and never returns


I'm trying to save user code scripts in RavenDB, and so far almost everything works. I got a script in from a separate process, and I am able to load the script, edit it, and save it back to the database.

The problem comes when I create a new script and try to insert it into the database. I use the code below.

public static void AddUserScript(UserScripts entity, string RavendbUrl, int userid)
{
    try
    {
    IvcRavenDB raven = new IvcRavenDB();
    var store = raven.InitRavenDB(RavendbUrl, "UserScripts");

    entity.Updated = DateTime.Now.ToString();
    entity.Created = DateTime.Now.ToString();
    entity.ScriptFileLength = entity.Script.Length;
    entity.userid = userid;

    using (var session = store.OpenSession())
    {
        session.Store(entity); // DIES HERE
        session.SaveChanges();
    }
    }
    catch (Exception ex)
    {
    var mess = ex.Message;
    }
}

When I say dies, the next line is not executed, there is no exception, and I see no error anywhere, which is very odd. Almost the EXACT same code works to save an entity with an Id, the only difference is that the Id field when adding is null.

I'm using RavenDB 4 with Raven Client 4.02 in ,Net Core 2.0.

I'm very new to Raven and don't even know where to start to figure this out without errors, so any help would be great.


Solution

  • For whatever reason, leaving the Id null is causing a problem, it may be the version of the client, I'm not sure. However I found two documents that describe a few ways to get the Id generated, and they all work consistently.

    4 ways to get the Id

    1. Semantic ID This ID was generated by entering the actual string in the document ID. i.e. "users/ayende@hr.com"

    2. Server-Side ID This ID was generated by entering: "users/" in the document ID.

    3. Identity This ID was generated by entering: "users|" in the document ID.

    4. GUID This ID was generated by leaving the document ID field empty

    More information can be found here: Document Identifier Generation