Connect to couchbase server

Hi,

May be this is very silly question. but somehow, I am not able to connect to couchbase.
when connecting to local couchbase and default bucket, it works. use below block in web.config file. but when try to connect to couchbase on other machine, it doesn’t work. it doesn’t even throw exception but get operation return null for the document.

use this for pulling document

CouchbaseClient cbClient = new CouchbaseClient();
var Doc_name = "Teacher." + UserId;
var doc = cbClient.Get(Doc_name);

Also, if I first installed couchbase first on 192.168.1.10 and then joined cluster of the same from 192.168.1.11 then in the web.config couchbase section, should I need to specify both the server IP(s) or only IP of 192.168.1.10.

will appreciate if you can answer these questions.

it’s couchbase version 4.0 and windows server 2012 R2.

– doesn’t work

<couchbase>
  <servers bucket="TestBucket" bucketPassword="TestPwd">
    <add uri="http://192.168.1.10:8091/pools" />
  </servers> 
</couchbase>

–works

<couchbase>
  <servers>
    <add uri="http://localhost:8091/pools" />
  </servers>
</couchbase>

Could you post output of http://localhost:8091/pools/default? I guess cluster renders for one of the nodes 127.0.0.1, so the client cannot connect to it.

Hi,
Thanks for your prompt response.

Following is output of http://localhost:8091/pools/default?

{
  "storageTotals": {
    "ram": {
      "total": 8589463552,
      "quotaTotal": 5152702464,
      "quotaUsed": 5152702464,
      "used": 3272646656,
      "usedByData": 39231176,
      "quotaUsedPerNode": 5152702464,
      "quotaTotalPerNode": 5152702464
    },
    "hdd": {
      "total": 85529194496,
      "quotaTotal": 85529194496,
      "used": 23092882513,
      "usedByData": 55606348,
      "free": 62436311983
    }
  },
  "serverGroupsUri": "/pools/default/serverGroups?v=63423893",
  "indexMemoryQuota": 256,
  "memoryQuota": 4914,
  "name": "default",
  "alerts": [],
  "alertsSilenceURL": "/controller/resetAlerts?token=0&uuid=1bb648d89192a003d0d16d8325376864",
  "nodes": [
    {
      "systemStats": {
        "cpu_utilization_rate": 19.74649766511007,
        "swap_total": 9931640832,
        "swap_used": 4335808512,
        "mem_total": 8589463552,
        "mem_free": 5381611520
      },
      "interestingStats": {
        "cmd_get": 0,
        "couch_docs_actual_disk_size": 55606348,
        "couch_docs_data_size": 55462604,
        "couch_spatial_data_size": 0,
        "couch_spatial_disk_size": 0,
        "couch_views_actual_disk_size": 0,
        "couch_views_data_size": 0,
        "curr_items": 453,
        "curr_items_tot": 453,
        "ep_bg_fetched": 0,
        "get_hits": 0,
        "mem_used": 39231176,
        "ops": 0,
        "vb_replica_curr_items": 0
      },
      "uptime": "194368",
      "memoryTotal": 8589463552,
      "memoryFree": 5381611520,
      "mcdMemoryReserved": 6553,
      "mcdMemoryAllocated": 6553,
      "couchApiBase": "http://192.168.1.250:8092/",
      "couchApiBaseHTTPS": "https://192.168.1.250:18092/",
      "otpCookie": "jkgjxmrbstcnuxnc",
      "clusterMembership": "active",
      "recoveryType": "none",
      "status": "healthy",
      "otpNode": "ns_1@192.168.1.250",
      "thisNode": true,
      "hostname": "192.168.1.250:8091",
      "clusterCompatibility": 262144,
      "version": "4.0.0-4051-enterprise",
      "os": "windows",
      "ports": {
        "sslProxy": 11214,
        "httpsMgmt": 18091,
        "httpsCAPI": 18092,
        "proxy": 11211,
        "direct": 11210
      },
      "services": [
        "index",
        "kv",
        "n1ql"
      ]
    }
  ],
  "buckets": {
    "uri": "/pools/default/buckets?v=12982791&uuid=1bb648d89192a003d0d16d8325376864",
    "terseBucketsBase": "/pools/default/b/",
    "terseStreamingBucketsBase": "/pools/default/bs/"
  },
  "remoteClusters": {
    "uri": "/pools/default/remoteClusters?uuid=1bb648d89192a003d0d16d8325376864",
    "validateURI": "/pools/default/remoteClusters?just_validate=1"
  },
  "controllers": {
    "addNode": {
      "uri": "/controller/addNodeV2?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "rebalance": {
      "uri": "/controller/rebalance?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "failOver": {
      "uri": "/controller/failOver?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "startGracefulFailover": {
      "uri": "/controller/startGracefulFailover?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "reAddNode": {
      "uri": "/controller/reAddNode?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "reFailOver": {
      "uri": "/controller/reFailOver?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "ejectNode": {
      "uri": "/controller/ejectNode?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "setRecoveryType": {
      "uri": "/controller/setRecoveryType?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "setAutoCompaction": {
      "uri": "/controller/setAutoCompaction?uuid=1bb648d89192a003d0d16d8325376864",
      "validateURI": "/controller/setAutoCompaction?just_validate=1"
    },
    "clusterLogsCollection": {
      "startURI": "/controller/startLogsCollection?uuid=1bb648d89192a003d0d16d8325376864",
      "cancelURI": "/controller/cancelLogsCollection?uuid=1bb648d89192a003d0d16d8325376864"
    },
    "replication": {
      "createURI": "/controller/createReplication?uuid=1bb648d89192a003d0d16d8325376864",
      "validateURI": "/controller/createReplication?just_validate=1"
    }
  },
  "rebalanceStatus": "none",
  "rebalanceProgressUri": "/pools/default/rebalanceProgress",
  "stopRebalanceUri": "/controller/stopRebalance?uuid=1bb648d89192a003d0d16d8325376864",
  "nodeStatusesUri": "/nodeStatuses",
  "maxBucketCount": 10,
  "autoCompactionSettings": {
    "parallelDBAndViewCompaction": false,
    "databaseFragmentationThreshold": {
      "percentage": 30,
      "size": "undefined"
    },
    "viewFragmentationThreshold": {
      "percentage": 30,
      "size": "undefined"
    },
    "indexFragmentationThreshold": {
      "percentage": 30
    }
  },
  "tasks": {
    "uri": "/pools/default/tasks?v=23780908"
  },
  "counters": null,
  "indexStatusURI": "/indexStatus?v=21137658"
}

Yes, and from the output, I can see that your node advertized as 192.168.1.250, so I guess this is why localhost works and 192.168.1.10 does not

My apology, I guess, I was not clear.
I have 2 servers. 192.168.1.250 and 192.168.1.10

250 is web server and if I host couchbase on the same it works fine as localhost. but when I try to connect to couchbase server on 10. issue occurs. I mean, no error generated but document object returned is null

Below is output from http://192.168.1.10:8091/pools/default

{
  "storageTotals": {
    "ram": {
      "total": 8588992512,
      "quotaTotal": 6291456000,
      "quotaUsed": 6291456000,
      "used": 6104014848,
      "usedByData": 77214232,
      "quotaUsedPerNode": 3145728000,
      "quotaTotalPerNode": 3145728000
    },
    "hdd": {
      "total": 128110813184,
      "quotaTotal": 128110813184,
      "used": 30106041098,
      "usedByData": 13927644,
      "free": 97364218020
    }
  },
  "serverGroupsUri": "/pools/default/serverGroups?v=88221562",
  "indexMemoryQuota": 256,
  "memoryQuota": 3000,
  "name": "default",
  "alerts": [],
  "alertsSilenceURL": "/controller/resetAlerts?token=0&uuid=931c1f728946a7242ba5bac231d9cbfd",
  "nodes": [
    {
      "systemStats": {
        "cpu_utilization_rate": 7.04647676161919,
        "swap_total": 5032693760,
        "swap_used": 3568787456,
        "mem_total": 4294496256,
        "mem_free": 1414844416
      },
      "interestingStats": {
        "cmd_get": 0,
        "couch_docs_actual_disk_size": 13910968,
        "couch_docs_data_size": 13787042,
        "couch_spatial_data_size": 0,
        "couch_spatial_disk_size": 0,
        "couch_views_actual_disk_size": 0,
        "couch_views_data_size": 0,
        "curr_items": 428,
        "curr_items_tot": 428,
        "ep_bg_fetched": 0,
        "get_hits": 0,
        "mem_used": 75634976,
        "ops": 0,
        "vb_replica_curr_items": 0
      },
      "uptime": "526244",
      "memoryTotal": 4294496256,
      "memoryFree": 1414844416,
      "mcdMemoryReserved": 3276,
      "mcdMemoryAllocated": 3276,
      "couchApiBase": "http://192.168.1.10:8092/",
      "couchApiBaseHTTPS": "https://192.168.1.10:18092/",
      "clusterMembership": "active",
      "recoveryType": "none",
      "status": "healthy",
      "otpNode": "ns_1@192.168.1.10",
      "thisNode": true,
      "hostname": "192.168.1.10:8091",
      "clusterCompatibility": 262144,
      "version": "4.0.0-4051-enterprise",
      "os": "windows",
      "ports": {
        "sslProxy": 11214,
        "httpsMgmt": 18091,
        "httpsCAPI": 18092,
        "proxy": 11211,
        "direct": 11210
      },
      "services": [
        "index",
        "kv",
        "n1ql"
      ]
    },
    {
      "systemStats": {
        "cpu_utilization_rate": 8.468734613490891,
        "swap_total": 5032693760,
        "swap_used": 3566477312,
        "mem_total": 4294496256,
        "mem_free": 1147453440
      },
      "interestingStats": {
        "cmd_get": 0,
        "couch_docs_actual_disk_size": 16676,
        "couch_docs_data_size": 0,
        "couch_spatial_data_size": 0,
        "couch_spatial_disk_size": 0,
        "couch_views_actual_disk_size": 0,
        "couch_views_data_size": 0,
        "curr_items": 0,
        "curr_items_tot": 0,
        "ep_bg_fetched": 0,
        "get_hits": 0,
        "mem_used": 1579256,
        "ops": 0,
        "vb_replica_curr_items": 0
      },
      "uptime": "2072917",
      "memoryTotal": 4294496256,
      "memoryFree": 1147453440,
      "mcdMemoryReserved": 3276,
      "mcdMemoryAllocated": 3276,
      "couchApiBase": "http://192.168.1.11:8092/",
      "couchApiBaseHTTPS": "https://192.168.1.11:18092/",
      "clusterMembership": "active",
      "recoveryType": "none",
      "status": "healthy",
      "otpNode": "ns_1@192.168.1.11",
      "hostname": "192.168.1.11:8091",
      "clusterCompatibility": 262144,
      "version": "4.0.0-4051-enterprise",
      "os": "windows",
      "ports": {
        "sslProxy": 11214,
        "httpsMgmt": 18091,
        "httpsCAPI": 18092,
        "proxy": 11211,
        "direct": 11210
      },
      "services": [
        "index",
        "kv",
        "n1ql"
      ]
    }
  ],
  "buckets": {
    "uri": "/pools/default/buckets?v=79202450&uuid=931c1f728946a7242ba5bac231d9cbfd",
    "terseBucketsBase": "/pools/default/b/",
    "terseStreamingBucketsBase": "/pools/default/bs/"
  },
  "remoteClusters": {
    "uri": "/pools/default/remoteClusters?uuid=931c1f728946a7242ba5bac231d9cbfd",
    "validateURI": "/pools/default/remoteClusters?just_validate=1"
  },
  "controllers": {
    "addNode": {
      "uri": "/controller/addNodeV2?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "rebalance": {
      "uri": "/controller/rebalance?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "failOver": {
      "uri": "/controller/failOver?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "startGracefulFailover": {
      "uri": "/controller/startGracefulFailover?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "reAddNode": {
      "uri": "/controller/reAddNode?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "reFailOver": {
      "uri": "/controller/reFailOver?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "ejectNode": {
      "uri": "/controller/ejectNode?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "setRecoveryType": {
      "uri": "/controller/setRecoveryType?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "setAutoCompaction": {
      "uri": "/controller/setAutoCompaction?uuid=931c1f728946a7242ba5bac231d9cbfd",
      "validateURI": "/controller/setAutoCompaction?just_validate=1"
    },
    "clusterLogsCollection": {
      "startURI": "/controller/startLogsCollection?uuid=931c1f728946a7242ba5bac231d9cbfd",
      "cancelURI": "/controller/cancelLogsCollection?uuid=931c1f728946a7242ba5bac231d9cbfd"
    },
    "replication": {
      "createURI": "/controller/createReplication?uuid=931c1f728946a7242ba5bac231d9cbfd",
      "validateURI": "/controller/createReplication?just_validate=1"
    }
  },
  "rebalanceStatus": "none",
  "rebalanceProgressUri": "/pools/default/rebalanceProgress",
  "stopRebalanceUri": "/controller/stopRebalance?uuid=931c1f728946a7242ba5bac231d9cbfd",
  "nodeStatusesUri": "/nodeStatuses",
  "maxBucketCount": 10,
  "autoCompactionSettings": {
    "parallelDBAndViewCompaction": false,
    "databaseFragmentationThreshold": {
      "percentage": 30,
      "size": "undefined"
    },
    "viewFragmentationThreshold": {
      "percentage": 30,
      "size": "undefined"
    },
    "indexFragmentationThreshold": {
      "percentage": 30
    }
  },
  "tasks": {
    "uri": "/pools/default/tasks?v=14082163"
  },
  "counters": {
    "rebalance_fail": 4,
    "rebalance_start": 5,
    "rebalance_success": 1
  },
  "indexStatusURI": "/indexStatus?v=22306480"
}

Hi @newsachins

There are a couple issues with the code you shared.

  1. It looks like you’re using an old version of the .NET client because CouchbaseClient was replaced with Cluster & Bucket for interacting with the server. The newest client version is 2.3.9 What client version are you using?

  2. You have setup the server list in your web.config but you haven’t instructed the client to use those settings. This is done with the 2.X SDK like this:

var cluster = new Cluster("couchbase"); // config section name
var bucket = cluster.OpenBucket("myBucket");

Further details on how to configure the client can be found here.

Also, in your initial post you asked if all server IPs need to added to the configuration - This is not the case because the client receives a complete list of servers in the cluster during it’s bootstrap process. The configuration list is just a way to make the initial contact.

Hope that helps.

Hello Mike,

Thanks for Prompt response. I appreciate it.
It seems, I have to upgrade couchbase.dll to newer version for resolving
connect issue.

somehow, during our development testing, Couchbase server stop responding
and we have to restart machine in order to make it operation.
Following is the log.
Can you please check and let us know what could be wrong ?

Service ‘goxdcr’ exited with status 1. Restarting. Messages:
MetadataService 2016-11-12T01:21:45.328-06:00 [ERROR]
metakv.ListAllChildren failed. path=/remoteCluster/, err=Get
http://127.0.0.1:8091/_metakv/remoteCluster/: CBAuth database is stale:
last reason: dial tcp 127.0.0.1:8091: ConnectEx tcp: No connection could be
made because the target machine actively refused it., num_of_retry=2
MetadataService 2016-11-12T01:21:45.328-06:00 [ERROR]
metakv.ListAllChildren failed. path=/remoteCluster/, err=Get
http://127.0.0.1:8091/_metakv/remoteCluster/: CBAuth database is stale:
last reason: dial tcp 127.0.0.1:8091: ConnectEx tcp: No connection could be
made because the target machine actively refused it., num_of_retry=3
MetadataService 2016-11-12T01:21:45.328-06:00 [ERROR]
metakv.ListAllChildren failed. path=/remoteCluster/, err=Get
http://127.0.0.1:8091/_metakv/remoteCluster/: CBAuth database is stale:
last reason: dial tcp 127.0.0.1:8091: ConnectEx tcp: No connection could be
made because the target machine actively refused it., num_of_retry=4
RemoteClusterService 2016-11-12T01:21:45.328-06:00 [ERROR] Failed to get
all entries, err=metakv failed for max number of retries = 5
[goport] 2016/11/12 01:21:45 c:/Program
Files/Couchbase/Server/bin/goxdcr.exe terminated: exit status 1

Regards,
Sachin

Hi @newsachins

The log you have provided looks to come from the XDCR process. This service is used to replicate documents between two separate Couchbase clusters. The log information indicates the target machine refused the connection but it’s hard to say why without more information.

Couple of questions:

  1. Have you configured XDCR on your cluster - so the same cluster or a remote one?
  2. Is the machine you’re connecting to, localhost, part of a larger cluster?
  3. Can you see any machine level logs to indicate firewall or network connectivity problems?

Thanks

Thanks for response.
It’s single machine. No cluster or nodes and it’s localhost.
Which logs should I check for providing more info?