Home > database >  Gremlin.Net.Driver.Exceptions.ConnectionClosedException
Gremlin.Net.Driver.Exceptions.ConnectionClosedException

Time:09-13

Created object for gremlinServer , connectionPoolSettings

    var gremlinClient = new GremlinClient(gremlinServer,connectionPoolSettings:connectionPoolSettings);

    using (gremlinClient)
    {
      var v1 = graph.AddV("person").Property("name", "marko").Next();**
      var v2 = graph.AddV("person").Property("name", "stephen").Next();
      graph.V(v1).AddE("knows").To(v2).Property("weight", 0.75).Iterate();
    }

At var V1 getting below exception:

Gremlin.Net.Driver.Exceptions.ConnectionClosedException: 'Connection closed by server. CloseStatus: InternalServerError, CloseDescription: Internal-Server-Error. Any in-progress requests on the connection will be in an unknown state, and may need to be retried.

I am not able to understand why the server is closing connection

CodePudding user response:

After you call Next() the first time that v1 object is now a result. Is graph the actual GraphTraversalSource, or something you spawned from it? If the latter, after the call to Next it has been completed and you will have to create it again.

In general, it would be better to have the first two calls that populate v1 and v2 return their IDs. Even better, do it all as one query. I will show examples of both below.

 var v1 = graph.AddV("person").Property("name", "marko").Id().Next();
 var v2 = graph.AddV("person").Property("name", "stephen")).Id().Next();
 graph.V(v1).AddE("knows").To(V(v2)).Property("weight", 0.75).Iterate();
}

or, cleaner,

 graph.AddV("person").Property("name", "marko").As("a").
       AddV("person").Property("name", "stephen")).
       AddE("knows").From("a").Property("weight", 0.75).
       Iterate();
}

I also assume that graph is a GraphTraversalSource object (commonly called g, and not an actual Graph object of something spawned from g.

CodePudding user response:

Since you tagged this question with Cosmos DB, I assume that you're using that backend. It unfortunately doesn't support any Gremlin.Net version newer than 3.4.13, but you mentioned in a comment that you are using Gremlin.Net 3.6.1 which cannot work with Cosmos DB right now.

Apart from the versions, Cosmos DB also does not support Gremlin Bytecode which is used internally when you create your traversals in C# and then iterate them. With Cosmos DB, you have to send them as string instead, just like you would send an SQL query string for example.

So, instead of this (I'm taking the code from kelvin-lawrence's response as it uses a single traversal):

graph.AddV("person").Property("name", "marko").As("a").
       AddV("person").Property("name", "stephen")).
       AddE("knows").From("a").Property("weight", 0.75).
       Iterate();

you have to do this:

var query =  "g.addV('person').property('name', 'marko').as('a').
       addV('person').property('name', 'stephen')).
       addE('knows').from('a').property('weight', 0.75).
       iterate()";
await gremlinClient.SubmitAsync<object>(query);

In general, please check the official Cosmos DB docs or this example repository for Cosmos DB and Gremlin.Net.

  • Related