0

I am trying to connect Azure Cosmos DB using Gremlin API through Gremlin.Net. I am getting this error:

System.Net.WebSockets.WebSocketException: 'Unable to connect to the remote server'

enter image description here

The credentials are

EndPointUrl: "localhost://8081",
Port: 443
database = "db1";
container = "coll1";
PrimaryKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";

I have installed Azure Cosmos DB Emulator and trying to connect it. And run the emulator using following command

CosmosDB.Emulator /EnableGremlinEndpoint

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
azhar rahi
  • 331
  • 4
  • 16

2 Answers2

0

Please try the following code:

        var gremlinServer = new GremlinServer(hostname: "localhost", port: 8901, username: "/dbs/db1/colls/col1", password: "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
        using (var gremlinClient = new GremlinClient(gremlinServer))
        {
            //Your code goes here....
        }

Basically the issue is that you need to use 8901 as the port (default port as per the instructions here) and use localhost as the host name. Using the code above, I was able to create an instance of GremlinClient.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • I will check it. How can I confirm that gremlinEndPoint is running on 8901? Can I see it using netstat? Also another problem is on one laptop when I run CosmosDB.Emulator /EnableGremlinEndpoint in cmd, it started and opened the localhost page but after some minutes, it shows an error message and then stops while on another machine it does not show the error message and hence does not stop. I am currently away from that laptop where emulator does not stop. – azhar rahi Jun 13 '20 at 23:12
  • I am feeling that Cosmos DB Emulator is not perfectly compatible. There must be auto-checks for missing files and auto-installations or at least list of missing files, features, registries etc – azhar rahi Jun 13 '20 at 23:14
  • I also struggle with Emulator. To answer your question, I ended up reinstalling it :). – Gaurav Mantri Jun 14 '20 at 06:19
  • I have tried reinstalling it but still the same issue. – azhar rahi Jun 14 '20 at 11:27
  • Did you run `CosmosDB.Emulator /EnableGremlinEndpoint` from an elevated command prompt? – Gaurav Mantri Jun 14 '20 at 11:30
  • Also I manually deleted the Cosmos DB Emulator related files from AppData folder after installing it (and before running it). – Gaurav Mantri Jun 14 '20 at 11:31
  • Yes Gaurav I removed cosmos files from AppData and Yes I ran CosmosDB.Emulator /EnableGremlinEndpoint from elevated command prompt. Its so frustating! – azhar rahi Jun 14 '20 at 12:14
  • Now I am trying to run it on Local Docker Container. Not sure if it helps! – azhar rahi Jun 14 '20 at 12:15
  • Oh! I did not run it in Docker container. Not sure if it helps, but can you try running `Microsoft.Azure.Cosmos.Emulator` instead of `CosmosDB.Emulator`? I tried running the former only. I am not sure the difference between the 2 executables. – Gaurav Mantri Jun 14 '20 at 12:18
  • Ok I will try Microsoft.Azure.Cosmos.Emulator too. I also dont know the difference but I have found articles using it as alternative. – azhar rahi Jun 14 '20 at 12:22
0

Check the file C:\sdk\apache-tinkerpop-gremlin-console-3.3.4\apache-tinkerpop-gremlin-console-3.3.4\conf\remote-localcompute.yaml, and make sure that the Gremlin endpoint is configured the same way in your code as it is in this file. It could be that the port you are using in your code is different, or that you have SSL enabled. That did the trick for me.

MarleneHE
  • 334
  • 4
  • 17