Nikita Bhopale
Nikita Bhopale

Reputation: 63

How to connect kusto database with C#?

WithAadUserPromptAuthentication mising so i cant use sample code which is provided by Microsoft documentation? That Is :

var serviceUri = "Service URI, typically of the form https://cluster.region.kusto.windows.net";
var authority = "contoso.com"; // Or the AAD tenant GUID: "..."

// Recommended syntax
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(serviceUri)
  .WithAadUserPromptAuthentication(authority);

// Legacy syntax
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(serviceUri)
{
    FederatedSecurity = true,
    InitialCatalog = "NetDefaultDB",
    Authority = authority,
};

// Equivalent Kusto connection string: $"Data Source={serviceUri};Database=NetDefaultDB;Fed=True;Authority Id={authority}"

Is there is any new solution instead of WithAadUserPromptAuthentication methode?

Upvotes: 4

Views: 7078

Answers (2)

Vladik Branevich
Vladik Branevich

Reputation: 1175

Microsoft.Azure.Kusto.Data.NETStandard is deprecated and is no longer maintained. Please use Microsoft.Azure.Kusto.Data package (.Net framework and .Net Core flavors).

This method is not available with .Net Core, only with the .Net framework package due to the authentication library used (ADAL). The workaround you can use with .Net Core is to trigger username/password authentication by setting the following properties manually on your KustoConnectionStringBuilder instance: FederatedSecurity, UserID, Password, Authority.

We are planning to release a new version of the package built with the next gen authentication library (MSAL) that will expose this method (interactive user auth) on all platforms.

Upvotes: 1

unknown
unknown

Reputation: 7483

I'm afraid WithAadUserPromptAuthentication has moved from KustoConnectionStringBuilder. Both Microsoft.Azure.Kusto.Data.NETStandard(6.1.8) and Microsoft.Azure.Kusto.Data(8.1.5) don't contain this method.

enter image description here enter image description here

You could try this example using ApplicationClientId and ApplicationKey. Or other methods from here.

var serviceUri = "Service URI, typically of the form https://cluster.region.kusto.windows.net";
var authority = "contoso.com"; // Or the AAD tenant GUID: "..."
var applicationClientId = <ApplicationClientId>;
var applicationKey = <ApplicationKey>;

// Recommended syntax
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(serviceUri)
    .WithAadApplicationKeyAuthentication(applicationClientId, applicationKey, authority);

// Legacy syntax
var kustoConnectionStringBuilder = new KustoConnectionStringBuilder(serviceUri)
{
    FederatedSecurity = true,
    InitialCatalog = "NetDefaultDB",
    ApplicationClientId = applicationClientId,
    ApplicationKey = applicationKey,
    Authority = authority,
};

// Equivalent Kusto connection string: $"Data Source={serviceUri};Database=NetDefaultDB;Fed=True;AppClientId={applicationClientId};AppKey={applicationKey};Authority Id={authority}"

Upvotes: 0

Related Questions