1

I am testing write/query time series data to/from InfluxDB v2 using c#. Basically I used pretty much the example provided in the WebInterface under Data->"Load Data"->"Client Libraries"->C#.

I can write to the database no problem but when I try to query the data, I got the exception
'An item with the same key has already been added. Key: result'.

The call that causes the problem is

    public async Task<List<InfluxDB.Client.Core.Flux.Domain.FluxTable>> QueryDB()
    {
        string bucket = "ABucket";

        var query = $"from(bucket:\"{bucket}\") |> range(start: -1m)";
        
        var tables = await client.GetQueryApi().QueryAsync(query, "MyOrganisation");

        // client is an instance of InfluxDBClient

        return tables;
    }

This crashes when it returns from the QueryAsync call above.

I have read the other post 1 and post 2 with a similar problem but after going through those and checking my code, I did not see anything that is identically named. I even changed a bunch of names to make sure nothing is repeated. But the problem is not going away.

If I remove the async call that there is no problem but then I cannot query the database if I did that.

Has anyone used the c# example provided by InfluxDB and succeeded?

Here is the stacktrace if it is of any help.

at InfluxDB.Client.Core.Internal.AbstractQueryClient.<>c.<.cctor>b__22_1(Exception e)
at InfluxDB.Client.Core.Internal.AbstractQueryClient.<Query>d__9.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at InfluxDB.Client.QueryApi.<QueryAsync>d__7.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MainApp.InfluxDBControl.<QueryDB>d__12.MoveNext() in D:\Test\TestProject\TestInfluxDB\InfluxDBControl.cs:line 104
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MainApp.MainTest.<CatchUpButton_Click>d__20.MoveNext() in D:\Test\TestProject\TestInfluxDB\MainAppForm.cs:line 171
stackoverblown
  • 734
  • 5
  • 10

1 Answers1

0

I ran into the same problem today and was able to solve it by creating a new Bucket.

When querying the Bucket I created during the setup, I found that there are a lot of tags in it. Among them, a tag named "result" containing the tags "compile_error", "runtime_error" and "success". My guess is that this is what was causing the error.

I'm not quite sure why this is a thing though. The new Bucket I created is completely empty, except for the data I put in it. So neither can I tell you, why the system seems to be wanting to use the same tag for storing log data as well as query results, not can I tell you why none of this is present in the newly created Bucket.

I'm not quite sure if this qualifies as an answer, but I found it a bit lengthy for a comment.

TigersEye120
  • 664
  • 1
  • 9
  • 28