Download and extract the Couchbase client library into a directory, and then right click on References|Add Reference... in the solution explorer, select the Browse tab and navigate to where you extracted the client. Select the Couchbase.dll and click OK to add these references to your project. See Figure 5.
Once the references have been made, you will want to add an
instance of CouchbaseClient to your project.
One of the best places to do this is in Global.asax.cs in the
Application_Start() method which is guaranteed to be run only once
during the lifetime of the application.
Add the following static instance variable to the
MvcApplication class:
public static CouchbaseClient CouchbaseClient { get; private set; }
Add the following line to the end of the
Application_Start() method:
CouchbaseClient = new CouchbaseClient();
Then add the method in Listing 4 below
Application_Start().
Listing 4, Application_End() method.
protected void Application_End() { CouchbaseClient.Dispose(); }
Now, in order for the CouchbaseClient to be
created at runtime, configuration to specify the bucket and server
address to connect to must be added. Edit the Web.config file and
add the following XML after the opening <configuration>
element:
Listing 5, Web.config
<configSections> <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/> </configSections> <couchbase> <servers bucket="private" bucketPassword="private"> <add uri="http://10.0.0.33:8091/pools/default"/> </servers> </couchbase>
You would replace 10.0.0.33 with the address of your server, and
also set your bucket and bucketPassword
attributes appropriately.