29 Apr 2019

How to install RavenDB on a VM in Azure (step-by-step, part 3)

RavenDB-del3-eng.jpg

This is a three part guide if you want to install RavenDB on a virtual machine in Azure. Sounds tricky? Then you may have missed part 1 and part 2 of the guide.


Logging in to RavenDB from your development machine

Now let’s try to open RavenDB studio from our local development machine. We start by entering the following in our browser (Where the IP-address is the public IP-address of our RavenDB server):

But we are presented with the following error, why?

The problem is that we from now on, must always use the full domain name for RavenDB, because how should the browser otherwise be able to know if we are talking to the correct server? Instead we use the full domain name:

Now we get past this error and we are instead faced with this error:

Now what? To authenticate as a user, we don’t use a traditional username/password that you might expect, instead we use client-side certificates. Sounds scary? Copy the administrator certificate generated on the server to your local machine and unzip it.

After unzip you will see the following files:

To install the certificate on your local machine, double-click on the Personal Information Exchange file (pfx) and click next through the import wizard. Do not try to import the .crt file!

After the import is done, close all instances of your Chrome browser and then start it again. Navigate to your RavenDB instance, in this case:

If the certificate is imported properly you will be presented with this dialog:

Press OK and now you are in!  

Sample database

Of course, we need some sample data to query and to help us with this task, the developers of RavenDB have amazingly added a built-in feature that will populate a database with data from the infamous Northwind database from Microsoft. 

In RavenDB Studio we first create a new database named Northwind.

Click on Create, and then go to the Settings menu where there is an option to Create Sample Data.

prinscreen-1-1-1.jpg

When the generation is done, you can go to the Documents view to see all the newly created documents.

prinscreen-2.jpg

Creating a user

Before we start accessing this database from .NET, we need to create a new user, we surely don’t want to run as administrator in the client! That would be a very bad idea and security risk. So, we navigate to the Manage Server -> Certificates page in RavenDB Studio.

prinscreen-3.jpg

Then we click on the Generate client certificate option under the Client certificate dropdown:

Then we fill out the form and select the Northwind database and for that database we choose Admin as our rights in that particular database. We need to have administrator rights in the Northwind database because we might want to create our own indexes from the client. You can read more about the database permissions here.

image2.png


(We enter edument as the certificate passphrase)

Click on Generate and after a few seconds a new certificate is generated and downloaded by your browser. Move the downloaded file to a more permanent location and in my case, I choose to place all my certificates in c:\Edument\Certificates

Unzip the .ZIP file and you should see the following files:

Azure key vault and RavenDB certificates
If you try to import certificates generated by RavenDB into Azure Key Vault you might experience import errors in the portal, if you have a problem then try to use an all lower-case certificate name or don’t use a certificate passphrase. 

Calling the database from .NET Core

Create a new .NET Core console application in Visual Studio and add the RavenDB.Client NuGet package:

Then we need to add the Northwind C# classes that represents the documents in the database and these can be found on the same page in RavenDB studio where you generated the sample data.

prinscreen-4.jpg

(Just copy the files to your project)

Then in your Main method we add the following code:

After that, when you run the application you should see a list of the 100 first companies in the database, sorted by name:

That’s it! We have successfully installed RavenDB and securely connected to it from a .NET Core application. Mission accomplished! Do you have any question or feedback? Please contact me: tore@edument.se 

About the author 

Tore Nestenius have passion for architecture, .NET and Web security. According to Tore "it is not possible to explain anything to anyone else but to understand it first". He is one of the founders of Edument and he is often on the move both in Sweden and abroad to hold courses. 

Related courses

  • C# Master Class

    This class teaches you how to take advantage of what C# and .Net offer. It takes a range of real-world problems, and uses modern C# and .Net features to build clean, well designed, multi-paradigm solutions.

    Category: .NET
    Duration: 3 days
    Price: 25 900 SEK
  • Software Architecture

    How do you avoid making your project a big ball of mud? How do you balance a wide range of design concerns and constraints? How do you map customer requirements to working software? This course provides you with the means and methods to face these challenges.

    Duration: 2 days
    Price: 21 500 SEK
  • Web Security for Developers

    The web is a great software delivery platform, making your software available to users around the world with zero installation and easily deployed updates. Unfortunately, it also exposes you to an army of adversaries - some human, some bot - who have darker goals: to cause loss to your data or reputation, subvert your resources for their own gain or attack your user base. 

    Duration: 2 days
    Price: 21 500 SEK
  • Beginning ASP.NET Core

    This course will give your ASP.NET Core development a solid start - in  the right direction! 

    Category: .NET
    Duration: 3 days
    Price: 25 900 SEK