In today's post, I'm going to show you how to create a clean Episerver database using a SQL script. As developers, we often want to experiment and tinker around with things locally. The annoying part of this exploratory development is that our development databases can often get destroyed or corrupted. Instead of having to remember to backup and restore your database, Episerver ships with a quick and easy way for us to create a clean database from scratch. In this post, you will learn some tips to make the restoration process less painful.
How To Create An Empty Episerver database?
The first thing you need to do is create a new empty database in SQL:
In SQL Manager, create a new database, by right-clicking on your database instance and selecting New Database
:
Give your database a name and a database owner:
In your website, update your connection string to point to your new database, as shown above:
In your Nuget package console window, you can now type Initialize-EPiDatabase
. This will then go off and create a new blank Episerver database!
Updating Your Database To The Right Patchset Version
After creating a database, it is very likely that you will also need to upgrade it to your version of the Episerver patchset. This can also be done in Nuget using:
When you reset your database, you will obviously lose all your web pages and site structure. If you don't want to lose your page data, I suggest you look at the Page Import/Export feature within the Episerver admin.
From this screen, you have several different backup options, depending on what you want to restore. Creating an export file is as simple as clicking the export
button
An XML file should now download to your computer:
You can then import the file back into Episerver using the importer, simple! Following this approach means you have a pretty powerful technique to do work, clear your database and re-import your content easily. Over the years, I've tried several different techniques to achieve a similar goal and by far this is the quickest and easiest approach. Happy Coding 🤘