.NET SDK doesn't appear to be formatting parameters


I have the following N1QL query:


(I can’t figure out how to get the bucket name escape characters `` to display in this editor, but they are surrounding $1).

I take that query and insert it into a QueryRequest object and iterate through a collection of parameters like so:

var query = new QueryRequest().Statement(N1QLQuery);

foreach (var param in positionalParameters)
    query = query.AddPositionalParameter(param);

I’m then left with a query that, when I hover over it in Visual Studio shows the following text:[{“statement”:“SELECT * FROM $1 WHERE $2 = ‘$3’ LIMIT 10 OFFSET 0”,“timeout”:“75000ms”,“metrics”:false,“args”:[“Lunch”,“my_type”,“PointOfInterest”,10,0],“creds”:[{“user”:“local:test-reader”,“pass”:“Timmy1”}],“client_context_id”:“1::4”}]

Once again, the special escape characters for the bucket name are there, they just don’t seem to be displaying correctly in this editor.

However, once I execute the query, I get the following error:

12003: Keyspace not found keyspace $1 - cause: No bucket named $1

If I don’t use positional parameters and instead just concatenate the parameters into a single string manually, the query executes (Although not successfully, I get a NewtonSoft JSON parse error on ‘results’ but thats another issue).

Am I doing something wrong here? The version of Couchbase I’m running is: Enterprise Edition 5.0.0 build 3519.


identifiers/fields can’t be parameterized (i.e Bucket name/keyspaces, fields in the documents), Only values can be parameterized. If don’t know upfront generate query dynamically when those available.

1 Like