簡體   English   中英

Kusto 使用 C# {kusto.data} 連接集群

[英]Kusto Connection with cluster using C# {kusto.data}

我正在嘗試使用 C# 建立與 Azure DataExplorer 集群的連接。我在https://docs.microsoft.com/en-us/azure/kusto/api/netfx/about-kusto-data 中引用了 C# 並安裝了 nuget在visual studio中打包kusto.data並復制代碼並在cmd提示符下運行dotnet,但它不起作用。

下面是我的代碼-

using Microsoft.Azure.Management.Kusto;
using System;

namespace LensDashboradOptimization
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            //var clusterUrl = "https://masvaas.kusto.windows.net";


            //var kcsb = new Kusto.Data.KustoConnectionStringBuilder(clusterUrl); 


            //Console.WriteLine(kcsb);
            // Read the first row from reader -- it's 0'th column is the count of records in MyTable
            // Don't forget to dispose of reader when done.

            var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://masvaas.windows.net/Samples;Fed=true");
            var reader = client.ExecuteQuery("MyTable | count");
            Console.WriteLine(reader);
        }
    }
}

我嘗試了fed=trueWithAadUserPromptAuthentication(); 兩者都不起作用。 我錯過了什么嗎?

您好,歡迎來到 Stack Overflow!

當我檢查這個時,我嘗試並遇到了類似的錯誤。 但問題出在我運行的 .Net Framework 版本上。 Kusto.Data包需要 .Net Framework 4.6.2 作為依賴項。 安裝后,我就可以安裝和導入包,隨后還可以連接到預期的 Kusto 集群並讀取數據。 這是對我有用的片段:

using System;
using Kusto.Data;

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var client = Kusto.Data.Net.Client.KustoClientFactory.CreateCslQueryProvider("https://help.kusto.windows.net/Samples;Fed=true");
            var reader = client.ExecuteQuery("StormEvents | sort by StartTime desc | take 10");

        }
    }
}

請仔細檢查依賴項,如果您仍然遇到問題,請告訴我。 希望這可以幫助!

using Kusto.Data;
using Kusto.Data.Common;
using Kusto.Data.Net.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

只有這些 using 語句才能完成您正在嘗試的工作。 為此,您需要從nuget gallery安裝 SDK。 此外,僅從上方安裝Microsoft.Azure.Kusto.DataMicrosoft.Azure.Management.Kusto 那就足夠了。

希望這有幫助。

您還可以查看更多內容:1) 靜態 IP 2) 安裝了 Azure 開發包的 VS 2019 社區版

對於 AadUserPromptAuthentication,現在不支持此方法,因為 kusto 數據庫首先需要對用戶進行身份驗證。 並且控制台應用程序無法打開提示窗口。 我建議使用 Web 應用程序。

暫無
暫無

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

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