Could not acquire server

I am getting the “Could not acquire server” exception. I have already seen the other post at “Could not acquire server - exception”, however, I did like to mention that in my case, the code works fine for the first call.

However, all subsequent calls fail!

Please suggest.

@jdconsults -

Could you post your code?

-Jeff

ClusterHelper.Initialize(GetClientConfiguration());
var bucket = ClusterHelper.GetBucket(“Coupons”);

        string query;
        if (fetchDetails == true)
            query = "SELECT c.* FROM `Coupons` c WHERE c.couponId = '" + coupId + "';";
        else
            query = "SELECT c.couponId, c.alphanumericCode, c.autoRedeem, c.createdOn, c.customerId, c.dateAvailableToCustomer, c.description, c.maxRedemptionCount, " +
                    "c.offerId, c.reasonIssued, c.redemptionChannel, c.redemptionCount, c.state, c.validStartDate, c.validEndDate " +
                    "FROM `Coupons` c WHERE c.couponId = '" + coupId + "';";

        var results = bucket.Query<Model.Coupon>(queryRequest);

        if (results.Success)
        {
            if (results.Rows.Count > 0)
                return results.Rows[0];
        }
        else
            return null;

I do understand that above calling ClusterHelper.Initialize(GetClientConfiguration()); is not good and that it should be done only as part of AppStart or so. But at this point I want to resolve the issue more than anything :slight_smile:

The first time I execute this code it works absolutely fine. However, the next time this method is hit, it gives me an exception at if(results.Success). Actually an exception is not thrown, however, in the Quick Watch window I can see that there is an Exception. The image for which I have pasted in my first post in this thread.

Got it.

Since the ClusterHelper caches references to the Cluster object and to each bucket that is opened, the act of re-initializing (calling ClusterHelper.Initialize(GetClientConfiguration());) is probably the issue. Just add the initialization to Application_Start and go from there…

-Jeff

I will write a Singleton implementation of my own CustomClusterHelper which would inherit from ClusterHelper and ensure that once initialized the same reference is returned. I hope this is OK.

I will let you know how it goes.

@jdconsults -

Sure, but by simply changing the scope we can easily determine if that is the issue…by adding more code, you may potentially introduce another bug or issue.

Alternatively, you can add logging and post your logs.

Also, which Couchbase version are you using and which SDK version?

-Jeff

I implemented a Singleton class and that WORKED!!!

Now all calls are returning me the value :slight_smile:

BTW, I am using Couchbase 4.1 and SDK 2.2.7

Thanks Jeff for your support!