簡體   English   中英

CosmosDB C#Gremlin-發送查詢時獲取異常

[英]CosmosDB C# Gremlin - Getting exception when sending query

摘自: https : //docs.microsoft.com/zh-cn/azure/cosmos-db/create-graph-dotnet

.wait()部分出現異常:

   NullReferenceException: Object reference not set to an instance of an object.

   at Gremlin.Net.Driver.Connection.ReceiveAsync[T]()
   at Gremlin.Net.Driver.Connection.SubmitAsync[T](RequestMessage requestMessage)
   at Gremlin.Net.Driver.ProxyConnection.SubmitAsync[T](RequestMessage requestMessage)
   at Gremlin.Net.Driver.GremlinClient.SubmitAsync[T](RequestMessage requestMessage)
   at Gremlin.Net.Driver.GremlinClientExtensions.SubmitAsync[T](IGremlinClient gremlinClient, String requestScript, Dictionary`2 bindings)

碼:

    private static string database = "db";
    private static string collection = "col";                                             
    private static string hostname = "grem-test.gremlin.cosmosdb.azure.com";
    public void test()
    {
        var gremlinServer = new GremlinServer(hostname, 443, enableSsl: true,
                                                username: "/dbs/" + database + "/colls/" + collection,
                                                password: authKey);
        var gremlinClient = new GremlinClient(gremlinServer);
        var grem = "g.V()";
        var t = gremlinClient.SubmitAsync<dynamic>(grem);
        t.Wait();

        foreach (var result in t.Result)
        {
            // The vertex results are formed as dictionaries with a nested dictionary for their properties
            string output = JsonConvert.SerializeObject(result);
            Console.WriteLine(String.Format("\tResult:\n\t{0}", output));
        }

它應該是:

    var task = gremlinClient.SubmitAsync<dynamic>(grem);
    task.Wait();

取自Gremlin C#示例:

                 // Create async task to execute the Gremlin query.
                var task = gremlinClient.SubmitAsync<dynamic>(query.Value);
                task.Wait();

我從使用示例應用程序開始:

        private static Task<ResultSet<dynamic>> SubmitRequest(GremlinClient gremlinClient, string query)
        {
            try
            {
                return gremlinClient.SubmitAsync<dynamic>(query);
            }
            catch (ResponseException e)
            {
                // They have extra stuff here for the request information that isn't relevant
                throw;
            }
        }

我從那里擴展,除了偶爾在嘗試另一個查詢仍在運行時運行查詢的例外情況之外,沒有任何問題。 我只能假設以這種方式運行查詢比直接調用SubmitAsync()更好。

我建議的另一件事是仔細檢查服務器參數的值,以防萬一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM