0

I am using kusto .net SDK to write to kusto database using c#.. I am able to create the table as I please, but I wish to be able to write some rows to the database and populate the columns "a" and "b".. couldn't find an easy way to do this online..

    static void Main(string[] args)
    {

        var KustoClusterConnectionString = $"xxxxxxxxxxxxxx";            
        var KustoDbName = "userGroup";            
        var AppId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
        var TenantId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
        var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
        
        var kcsb = new KustoConnectionStringBuilder(KustoClusterConnectionString)
        {
            InitialCatalog = KustoDbName,
            FederatedSecurity = true,
            ApplicationClientId = AppId,
            ApplicationKey = clientSecret,
            Authority = TenantId
        };                     

        var tableName = "userGroup";  
        using (var kustoClient = KustoClientFactory.CreateCslAdminProvider(kcsb))
        {
            var command =
                CslCommandGenerator.GenerateTableCreateCommand(
                    tableName,
                    new[]
                    {
            //Tuple.Create("TimeStamp", "System.DateTime"),
            Tuple.Create("a", "System.String"),
            Tuple.Create("b", "System.String"),

                    });

            kustoClient.ExecuteControlCommand(KustoDbName, command);
        }
      }

1 Answer 1

2

there are several code samples in this repo: https://github.com/Azure/azure-kusto-samples-dotnet

specifically - this project/file: https://github.com/Azure/azure-kusto-samples-dotnet/blob/master/client/HowToDataIngestion/Program.cs

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I did see this, but I don't wish to do it from a json file, I just want to have 2 variables(strings) and have a simple code to be able to ingest into the table..
ingesting a few records at a time isn't recommended in Production scenarios. if you still want to do so, you can invoke the .ingest inline control command, using the ExecuteControlCommand method you're already calling: learn.microsoft.com/en-us/azure/data-explorer/kusto/management/…. to generate the command's text, you can use CslCommandGenerator.GenerateTableIngestPushCommand(...), that's included in the client library
Yes, however, CslCommandGenerator.GenerateTableIngestPushCommand() still asks for string csvData... do you have an example that formats this.../calls this function?
alternatively, you can create the string on your own, e.g. var value1 = "hello"; var value2 = "world"; var tableName = "mytable"; var cmd = $".ingest inline into table {tableName} <| {value1},{value2}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.