.NET SDK Querying Issue

Hi There,

I am having an issue executing N1QL Queries in the .NET client. The exception is cannot connect to a remote server. I have not has any issues doing basic CRUD operations using the key-value pairs. Additionally, I can execute N1QL queries using the Query Workbench on the server, creating a Postman request, and using RestSharp on the .NET client. I have opened all the ports on the server and checked the firewall.

SDK Version: 2.5.3
Couchbase Server: Community Edition 5.0.0 build 3519
Server: Ubuntu 14.04


public override dynamic Query(string query, string type)

        // Open the bucket
        IBucket bucket = ClusterHelper.GetBucket(bucketName);

        // Create a new query
        IQueryRequest queryRequest = new QueryRequest(query);

        // Execute the query
        IQueryResult<dynamic> result = bucket.Query<dynamic>(queryRequest);

        // Loop through each row in the return query
        foreach (var row in result.Rows)

        return result.Rows;

Many Thanks!


Hi @tracet51 -

I don’t see anything wrong with your code, of course I cannot see the configuration, but it looks good to me. The error indicates that the client cannot reach the server using port 8093; which makes me think that something is blocking the request. Perhaps you are running Fiddler or another HTTP proxy?

Perhaps you can enable logging and post a single query request? Also, a full stacktrace would also help.


Hi Jeff,

After trying to re-configure I still cannot figure out the issue. Below is the error I am getting. Once again, this only happens when querying from the SDK. All other SDK features work, and querying via REST also works All the ports are open.

{“An error occurred while sending the request.”}

Exception Stacktrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Couchbase.N1QL.QueryClient.d__15`1.MoveNext()

Exception Message:
An error occurred while sending the request

InnerException Stacktrace:
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)

{“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.xxx.xxx.xxx:8093”} (10.xxx.xxx.xxx is the internal IP address)

InnerException Message:
Unable to connect to the remote server

Many thanks,


This part is pretty clear though. It looks like something else is blocking ports?

Maybe it’d be good to verify from a different utility.

To help diagnose if there is something blocking ports you could try our new experimental project that @brett19 has been working on to make it easier to diagnose environmental problems. Its working name at the moment is SDK doctor. Maybe try running it in that env? It may not find anything, but it will validate that common connectivity problems aren’t there.

You’ll find pre-built binaries on the release page.

Usually the summary at the end is pretty easy to interpret. If you need help with interpretation, please feel free to post it or a link to it here.

1 Like

Here is the solution I came to after reading the Couchbase forums:

The internal IP address was being used for the querying service but not for Key-Value stuff (even though I bootstrapped against the external IP address and could query against the external IP on port 8093). For some reason the combination of using Google Cloud Platform and the internal mapping of the cluster nodes, I could not set the Host Name / ip address to the external IP address. So in the SDK (even though I connected via my VM’s external IP), it was using the internal IP (10.x.x.3:8093) for querying. This IP could not be found on my development machine because Couchbase is being hosted on Google Cloud Platform.

So I changed the “hosts” file on Ubuntu /etc/hosts to create an alias name for the internal IP. That way the server could have a name when Couchbase bootstrapped. This mapped a domain name like “couchbase.test.internal1.nodes” to the internal IP address. This name would then be returned to the .NET SDK where it could then be further resolved.

On Windows I made the address “couchbase.test.internal1.nodes” resolve to the server’s true external/public IP address. I change the C:\Windows\System32\drivers\etc\hosts file to resolve couchbase.test.internal1.nodes to my server’s external/public IP address. That way when Couchbase bootstrapped against the external IP and the internal map was returned, it returned a name that could then be resolved to an external IP instead of returning the internal IP address (which is the default / only Host Name/IP Address that worked when configuring the server).

This was only necessary because of the selected development environment listed below.


ASP.NET (.NET SDK) running locally on Windows 10 and IIS
Couchbase 5.0.1 Build 5003
Ubuntu 16.04 on Google Cloud Platform

1 Like