2015-12-16 59 views
0

在我的C#代碼,我想創建一個使用構造函數版本Couchbase客戶端,我可以在bucketName傳遞和密碼:在C#代碼中設置Couchbase客戶端桶密碼

​​

在我的web.config文件在<couchbase>部分看起來是這樣的:

<couchbase> 
    <servers bucket="beer-sample" bucketPassword=""> 
    <add uri="localhost:8091/pools" /> 
    </servers> 
</couchbase> 

而在代碼中,我試圖通過創建一個Couchbase客戶端:

var cc = new CouchbaseClient("beer-sample", "ThePassword"); 

上述行總是失敗,並顯示錯誤「找不到註釋」。誰能幫忙?

回答

1

首先,您使用的是舊版本的Couchbase .Net SDK。 CouchbaseClient是使用Couchbase的舊方式。

請參閱新指南 - >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"); 
    } 

希望它能幫助。

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

相關問題