在我的C#代码中,我想使用我可以在bucketName和密码中传递的ctor版本创建一个Couchbase客户端:
//
// Summary:
// Initializes a new instance of the Couchbase.CouchbaseClient class using the
// default configuration and the specified bucket.
//
// Remarks:
// The configuration is taken from the /configuration/Couchbase section.
public CouchbaseClient(string bucketName, string bucketPassword);
在我的web.config文件中,<couchbase>
部分如下所示:
<couchbase>
<servers bucket="beer-sample" bucketPassword="">
<add uri="localhost:8091/pools" />
</servers>
</couchbase>
在代码中,我尝试通过以下方式创建Couchbase客户端:
var cc = new CouchbaseClient("beer-sample", "ThePassword");
以上行始终失败,错误&#34;无法找到注释&#34;。有人可以帮忙吗?
答案 0 :(得分:1)
首先,您使用的是旧版Couchbase .Net SDK。 CouchbaseClient是使用Couchbase的旧方式。
请参阅新指南 - &gt; http://docs.couchbase.com/developer/dotnet-2.1/dotnet-intro.html
其次,您必须使用您想要的密码创建您的存储桶。
例如:
var clientConfiguration = new ClientConfiguration();
clientConfiguration.Servers = new List<Uri> { new Uri("http://localhost:8091") };
Cluster Cluster = new Cluster(clientConfiguration);
using (var bucket = Cluster.OpenBucket("bucketpwd", "1234"))
{
Console.WriteLine("Bucket Opened");
}
希望它有所帮助。
答案 1 :(得分:1)
一个古老的话题,但也许可以帮助遇到同样问题的人。
我当前正在使用沙发床.net客户端2.7.5
var clusterConfig = new ClientConfiguration
{
Servers = new List<Uri>{new Uri("http://couchbase0-node.io:8091")},
PoolConfiguration = new PoolConfiguration()
};
using (var cluster = new Cluster(clusterConfig))
{
var authenticator = new PasswordAuthenticator(username, password);
cluster.Authenticate(authenticator);
using (var bucket = cluster.OpenBucket(bucketName))
{
// Do something like :
var data = await bucket.GetAsync<T>(cacheKey);
// Other staff
}
}
更多信息:https://docs.couchbase.com/dotnet-sdk/2.7/start-using-sdk.html
答案 2 :(得分:0)
请参阅Couchbase Server 3.0 / 3.1的此文档
ClientConfiguration example
var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri("http://192.168.56.101:8091/pools"),
new Uri("http://192.168.56.102:8091/pools"),
new Uri("http://192.168.56.103:8091/pools"),
new Uri("http://192.168.56.104:8091/pools"),
},
UseSsl = true,
DefaultOperationLifespan = 1000,
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{"default", new BucketConfiguration
{
BucketName = "default",
UseSsl = false,
Password = "",
DefaultOperationLifespan = 2000,
PoolConfiguration = new PoolConfiguration
{
MaxSize = 10,
MinSize = 5,
SendTimeout = 12000
}
}}
}
};
using (var cluster = new Cluster(config))
{
IBucket bucket = null;
try
{
bucket = cluster.OpenBucket();
//use the bucket here
}
finally
{
if (bucket != null)
{
cluster.CloseBucket(bucket);
}
}
}
}
http://docs.couchbase.com/developer/dotnet-2.1/configuring-the-client.html