I’m trying myself to find the way to get the collection for a Web Form application from Couchbase.
A simple asxp page is the following:
<%@ Page Language=“C#” EnableSessionState=“ReadOnly” Debug=“true” Async=“true” %>
<%@ Import Namespace=“System.Threading.Tasks” %>
<%@ Import Namespace=“Couchbase” %>
<%@ Import Namespace=“Couchbase.KeyValue” %>
<%@ Import Namespace=“Couchbase.Core.IO.Transcoders” %>
<%@ Import Namespace=“Couchbase.Management.Buckets” %>
async Task<ICluster> InitializeClusterAsync(String Uri, String Bucket, String Username, String Password) {
var options = new ClusterOptions() {
KvTimeout = TimeSpan.FromSeconds(5),
ManagementTimeout = TimeSpan.FromSeconds(12),
EnableDnsSrvResolution = false,
UserName = Username,
Password = Password,
EnableTls = false,
EnableConfigPolling = false,
MaxKvConnections = 25
};
var cluster = await Couchbase.Cluster.ConnectAsync(Uri, options).ConfigureAwait(false);
//await cluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
return (cluster);
}
private async Task<ICouchbaseCollection> GetCollection(ICluster _cluster) {
var bucket = await _cluster.BucketAsync("default").ConfigureAwait(false);
return (bucket.DefaultCollection());
}
<%
var _cluster = InitializeClusterAsync(“couchbase://127.0.0.1”, “default”, “xxx”, “yyy”).GetAwaiter().GetResult();
var _collection = GetCollection(_cluster).GetAwaiter().GetResult();
%>
Although the same code is working when i make a desktop app, on the web page is not working. 2 problems:
- Althought the bucker “default” exists, i get the exception on the following line
var bucket = await _cluster.BucketAsync(“default”).ConfigureAwait(false);
[BucketNotFoundException: Bucket with name default does not exist]
Couchbase.Core.d__51.MoveNext() +1213
- If i enable the line
await cluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10)).ConfigureAwait(false);
I get the following exception
[NotSupportedException: Cluster level WaitUntilReady is only supported by Couchbase Server 6.5 or greater. If you think this exception is caused by another error, please check your SDK logs for detail.]
Couchbase.d__29.MoveNext() +1951
For sure Couchbase is version 6.6 and bucket “default” exists. As i told the same piece of code on a desktop app works on the same server.
Any clue on what is going on? Can we have some solid examples of how we can setup things on Web applications using global.asax, web.config, etc?