Updates

Getting Started local development with Azure Cosmos DB services – Part 2

May 29, 2017 .NET, .NET Core 1.0, .NET Core 1.0.1, .NET Framework, ASP.NET, Azure, Azure SDK Tools, Azure Tools, Cloud Computing, CodeSnippets, CosmosDB, Document DB, Microsoft, PaaS, SaaS, Visual Studio 2015, Visual Studio 2015 Update 3, Visual Studio 2017, VisualStudio, VS2015, VS2017, Windows, Windows 10, Windows Azure Development, Windowz Azure No comments

In my previous article we discussed about setting local development environment using Cosmos DB Emulator for Windows. With this part 2 of the article, we will cover developing, debugging and integration related aspects of using Cosmos DB Emulator.

Developing with Cosmos DB Emulator

Once you have Cosmos DB emulator installed and running on your machine, you can use any supported Cosmos DB SDK or Cosmos DB REST API to interact with emulator. This process is same as you are using a Cosmos DB cloud service.

Cosmos DB Emulator also provides a build-in visual explorer through which you can view,create and edit collections and documents.

image

Before you integrate Cosmos DB SDK or Cosmos DB REST API you would need to generate master key for authentication. Unlike cloud service, Cosmos DB emulator only support single fixed account and master key.  You would not be able to communicate with Emulator without this master key.

Default Master Key:

Account name: localhost:<port>

Account key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==

PS: This key is only to be used in Emulator. You cannot use the same key for Production(Cosmos DB Cloud Service).

Furthermore, if you want to set your own key. You can go to command line references and run DocumentDB.Emulator.exe with sufficient command switch to set your own key. Remember it should meet the key security requirements. See command-line tool reference for more information.

The Azure Cosmos DB Emulator is installed by default to the C:\Program Files\Azure Cosmos DB Emulator  or C:\Program Files\DocumentDB Emulator  directory.

Once you have account name and key, you are good to go with development and debugging using Azure Cosmos DB emulator.

Let us start looking at how to use CosmosDB SDK. Once you add Cosmos DB SDK for .NET from NUGET sources. You would need to import the following namespaces to reference necessary classes.

 using Microsoft.Azure.Documents;
   
 using Microsoft.Azure.Documents.Client;
   
 using Microsoft.Azure.Documents.Linq;

Simple code to establish connection:

// Connect to the Azure Cosmos DB Emulator running locally use DocumentClient class in : 
DocumentClient client = new DocumentClient(
    new Uri("https://localhost:8081"), 
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

In the above code block we are directly embedding endpoint, key in the source code.But as a suggested approch keeping in mind to easily point to production service would be maintain the key in Web.config appSettings.

   <add value="https://localhost:8081/" key="endpoint"/>
    <add value="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" key="authKey"/>
 

Add NuGet reference to Microsoft.Azure.DocumentDB  (always use the latest version of the library)

image

For the ease of this article, I am going to use the existing ToDoList sample from DocumentDB Samples provided by Microsoft. You can originally find the same source from C:\Program Files\DocumentDB Emulator\Packages\DataExplorer\quickstart.

image

Copy and Unzip DocumentDB-Quickstart-DotNet.zip and open todo.sln in Visual Studio 2017 and your solution structure will look like below:

image

Now run the application in your Visual Studio.

1. You will see an initial screen:

image

2. Click on Create New:

image

3. New record will be added to your Azure Cosmos DB Emulator:

image

4. To verify in Cosmos DB emulator now open Cosmos DB explorer, click on Collections and Select ToDoList

image

5.Expand Documents and select item with id:da305da3-c1dc-4e34-94d9-fd7f82d26c58

image

Hope this article was helpful for you with initial development.  Share your feedback through comments and share this to your friends and colleagues.

Useful Links:

.NET Core 1.0.1 Update (September 2016) Available

September 14, 2016 .NET, .NET Core 1.0, .NET Core 1.0.1, .NET Framework, ASP.NET, ASP.NET Core 1.0, ASP.NET Core 1.0.1, HotFixes, Linux, Mac OSX, Microsoft, Open.Source, OpenSource, Operating Systems, Updates, Visual Studio 2015, Visual Studio 2015 Update 3, Visual Studio Code, VisualStudio, VS2015, Windows, Windows No comments

Microsoft .NET Core team has released an update to .NET Core 1.0, versioned as “.NET Core 1.0.1”.

Read more detailed updates from Microsoft Developer Announcement Blog: Announcing September 2016 Updates for .NET Core 1.0

You can read the release notes for .NET Core, ASP.NET Core and Entity Framework 1.0.1 to learn about the specific changes that are included, including the commits that the release was built from.

You can download associated tooling updates from below links:

Microsoft Visual Studio 2015 Update 3 – hotfix build – 14.0.25422.1 (KB3165756)

July 14, 2016 .NET, HotFixes, Microsoft, Updates, Visual Studio 2015, Visual Studio 2015 Update 3, VisualStudio, VS2015 No comments

Microsoft has released a hot-fix for Visual Studio 2015 Update 3, to fix certain critical issues identified after the release of Update 3.

Supported Version Visual Studio 2015 Update 3
File name VS14-KB3165756.exe
Date published 07/12/2016
File size 2.4 MB
This update applied to:
  • Visual Studio Professional 2015
  • Visual Studio Enterprise 2015
  • Visual Studio Community 2015
  • Visual Studio Express 2015 for Web
  • Visual Studio Express 2015 for Desktop
  • Visual Studio Express 2015 for Windows 10
What’s Fixed ?: Refer to knowledge-base article KB3165756

This update can be downloaded from Microsoft Download Center here

Visual Studio 2015 Update 3 – Download

June 27, 2016 .NET, .NET Core 1.0, .NET Framework, .NET Framework 4.5, .NET Framework 4.5.2, .NET Framework 4.6, ASP.NET, ASP.NET 5.0, ASP.NET Core 1.0, ASP.NET MVC, C#.NET, Community, JavaScript, Microsoft, MSDN, Trial Downloads, Updates, Visual Studio 2015, Visual Studio Code, Visual Studio SDK, VisualStudio, VS2015, WCF, Web API v2.0, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Azure, Windows Azure Development, Windows Phone Development, Windows Phone SDK, Windows Store Development, WPF, WWF, XAML No comments

Today Microsoft has released Update 3 for Visual Studio 2015. Visual Studio 2015 Update 3 includes a variety of capability improvements and bug fixes. To find out what’s new, see the Visual Studio 2015 Update 3 Release Notes. For a list of fixed bugs and known issues, see the Visual Studio 2015 Update 3 MSDN Article.

Download:
Visual Studio Community 2015 with Update 3 – Web Installer –  ISO
Visual Studio Enterprise 2015 with Update 3 – Web Install –  ISO
Visual Studio Professional 2015 with Update 3 – Web Installer –  ISO
Visual Studio 2015 Update 3 – Web InstallerISO
Visual Studio Team Foundation Server 2015 with Update 3 – Web Installer –  ISO
Visual Studio Test Professional 2015 – Web Installer – ISO
Visual Studio Express 2015 for Windows 10 – here
Visual Studio Express 2015 for Web – here
Visual Studio Express 2015 for Desktop – here

Visual Studio 2015 RC–Download

April 30, 2015 .NET, .NET Framework, .NET Framework 4.6, ASP.NET, ASP.NET 5.0, ASP.NET AJAX, ASP.NET MVC, BCL(Base Class Library), Microsoft, Microsoft SDKs, MSDN, Portable Class Library, SignalR, Trial Downloads, Updates, Visual Studio 2015, VisualStudio, VS2015, Web API, Web API v2.0, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Phone 8.0 SDK, Windows Phone SDK 2 comments

During #Build2015 event Microsoft has unveiled Visual Studio 2015 RC (Release Candidate) with lots of improvements and fixes to CTP version of Visual Studio. RC would be a near release quality and your see it is stable than ever.

Release Date: 29/APR/2015
Release Notes: View Release notes

Download

Other Associated Products

Visual Studio 2015 – ctp6

February 23, 2015 .NET, .NET Framework, ASP.NET, ASP.NET 4.5, Azure, Azure SDK, BCL(Base Class Library), C#.NET, IE, IIS, Microsoft SDKs, Portable Class Library, SQL Azure, SQL Server, Updates, Visual Studio SDK, VisualStudio, VS2015, WCF, Web API, Windows Phone SDK, Windowz Azure No comments

Microsoft today has released Visual Studio 2015 Community Technology Preview 6 (CTP 6), which includes some new features and improvements, such as new UI debugging tools for XAML, new Control Flow Guard security tool, and feature updates to ASP.NET framework.

For more information about what’s new in this release, please see the release notes.

Download Visual Studio 2015 Ultimate (web | iso)