1
votes

I'm trying to establish connection to Azure DataExplorer cluster using C# .. I referenced the C# in https://docs.microsoft.com/en-us/azure/kusto/api/netfx/about-kusto-data and installed nuget package kusto.data in visual studio and copied the code and did dotnet run in cmd prompt, but it didn't work.

Below is my code-

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);
        }
    }
}

I tried both fed=true and WithAadUserPromptAuthentication(); both didn't work. Am I missing something?

3
You may want to clarify what "didn't work" means, for instance specify what was the actual behavior, and if there was an error message - include it - Yoni L.
Hi @YoniL ,I have installed Microsoft.azure.kusto.data nuget package in visual studio. I m getting below error , Program.cs(1,17): error CS0234: The type or namespace name 'Azure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\v-vasub\Documents\LensDashboradOptimization\LensDashboradOptimization.csproj] The build failed. Fix the build errors and run again. - vaishnavi

3 Answers

0
votes

Hello and welcome to Stack Overflow!

I tried and faced a similar error when I was checking this out. But the issue turned out to be with the version of .Net Framework that I was running. The Kusto.Data package requires .Net Framework 4.6.2 as a dependency. When I had that installed, I was able to install and import the package, and also subsequently connect to the intended Kusto cluster and read data. This is the snippet that worked for me:

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");

        }
    }
}

Please double check on the dependencies and let me know if you still run into issues. Hope this helps!

0
votes
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;

Only these using statement do the job that you are trying to. For that all you need to install SDK from nuget gallery . Also, only install Microsoft.Azure.Kusto.Data and Microsoft.Azure.Management.Kusto from above. That is sufficient.

Hope this help.

Few more things you can look on as: 1) Static IP 2)VS 2019 community edition with Azure dev packages installed

0
votes

WithAadUserPromptAuthentication, this method is not supported now as kusto database first need authentication for the user. and the console application is not able to open a prompt window. I recommend to use a web application.