Can you help me with configuring the buckets in web.config in a .net project.
I want to use 3 buckets in my application and would like to keep the bucket details in web.config and call it using a Key or something into the the Data Access layer.
Can you help me with configuring the buckets in web.config in a .net project.
I want to use 3 buckets in my application and would like to keep the bucket details in web.config and call it using a Key or something into the the Data Access layer.
To configure the buckets, you just need to use multiple tags, one for each bucket. You can see a sample of the XML configuration format in the “Configuration with an App.Config or Web.Config” section here:
http://developer.couchbase.com/documentation/server/4.1/sdks/dotnet-2.2/configuring-the-client.html
Once you configure the buckets, you’ll need to use that configuration. To do this, call ClusterHelper.Initialize(“couchbaseClients/couchbase”) in your Global.asax file. Note that the string is the XML path to the configuration you made in the previous step.
Finally, whenever you need a bucket call ClusterHelper.GetBucket(“bucketname”). You can even add this to your dependency injection system pretty easily. The only gotcha is that you should not call Dispose on the returned bucket. It’s returning a shared instance which will be reused with each call to GetBucket.
Examples of the second and third steps above can be found here:
http://developer.couchbase.com/documentation/server/4.1/sdks/dotnet-2.2/cluster-helper.html
Brant
Thanks @btburnett3 .
So, I understand that we need to explicitly say the bucket name in the Program, am I understanding it right?
Can you tell me is there any way to keep the multiple bucket names in the web.config and call it using some key or so inside the ClusterHelper.GetBucket(“bucketname”). Because I feel its not wise to call bucket name in codes and also if kept inside web.config, it will be more maintainable in case any changes in bucket config/password comes later. Any suggestion
My recommendation would be to put the bucket names in AppSettings. Then in code you would just be referencing the AppSetting key, and the value would be the bucket name. I don’t believe there is a way to do this built into the SDK.
Brant
Thanks @btburnett3
I have also incorporated the session provider, after referring the below article
http://blog.couchbase.com/2016/march/couchbase-asp.net-integration-beta-3-release
Do we have any option to add security to connect to buckets in Couchbase.? How can I give Cluster Credentials (Username, Password ) in web.config to implement Authentication?
When you setup your bucket, you can add a password to it. You can then add this password to your bucket configuration in your config file using the password=“” attribute.
For additional security, you can also use SSL to communicate to Couchbase. Just use useSsl=“true” in the configuration file. For SSL, you’ll also have to work with certificates as well. More information is available here:
http://developer.couchbase.com/documentation/server/4.1/sdks/dotnet-2.2/configuring-ssl.html
Brant
Hi Nitisha,
Were you able to figure out a way to pass the cluster credentials from web config ? I am trying to do something similar as i am unable to open a bucket without authenticating it with cluster credentials. This was not required in the earlier version of couchbase but after i upgraded it to version 5, it expects the bucket to be authenticated. If i don’t authenticate it i am getting the below exception.
Could not bootstrap - check inner exceptions for details.
at Couchbase.Core.ClusterController.CreateBucketImpl(String bucketName, String password, IAuthenticator authenticator)
at Couchbase.Core.ClusterController.CreateBucket(String bucketName, String password, IAuthenticator authenticator)
at Couchbase.Cluster.OpenBucket(String bucketName, String password)
at Couchbase.Cluster.OpenBucket(String bucketname)
at DPEUtiltites.ViewModels.ChkCouchBaseConnectionViewModel.d__8.MoveNext() in C:\TFS\DPE Utilities\CheckDBConnectionApp\CheckDBConnectionApp\ViewModels\ChkCouchBaseConnectionViewModel.cs:line 53
For example the code snippet earlier was as given below and this does not work in Couchbase version 5.
var cluster = new Cluster(config);
var bucket = cluster.OpenBucket(“TestBucket”);
Now, it expects the cluster to authenticated before it is open. And this works.
var cluster = new Cluster(config);
cluster.Authenticate(“Administrator”, “Administrator”);
var bucket = cluster.OpenBucket(“TestBucket”);
Did you come across this issue? And also please let me know how you are passing the cluster credentials if you were able to figure out a way by passing it from couchbase config section.
Thanks and Kind Regards,
Prashanth
@btburnett3 Hi Brant, could you please help me with the above issue?
Thanks and Kind Regards,
Prashanth
Hi @prashanth.mp7 -
Read the post flagged as solution in this thread: CreateManager using credentials from app.config - #4 by MikeGoldsmith
Basically the password and username are now root level constructs w/RBAC and Couchbase 5.0.
Thanks,
Jeff
Hi Jeff,
Thank you for the quick response.
I tried the following solution described in the below stack-overflow thread to authenticate the bucket and this seems to work for me. I can use your solution for passing the credentials through web config. Thank you so very much!
Thanks and Kind Regards,
Prashanth