- 0 kr
How to install RavenDB on a VM in Azure (step-by-step, part 3)
Part 3 in 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!
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.
When the generation is done, you can go to the Documents view to see all the newly created documents.
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.
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.
(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.ClientNuGet 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.
(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: email@example.com
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.
Författare: Tore Nestenius