Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: .NET (C#) 1.1
Community Wiki and Resources
Wiki: .NET Client Library
Download Client Library
.NET Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
2 Couchbase and ASP.NET MVC 3 Tutorial
Chapter Sections
Chapters

2.3. Stage 2: Adding and Configuring the Client Library

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.

Figure 2.5. Figure 5, Adding Couchbase references.

Adding Couchbase references.

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.