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:

How To Create A New Episerver Database 1

In SQL Manager, create a new database, by right-clicking on your database instance and selecting New Database:

How To Create A New Episerver Database 2

Give your database a name and a database owner:

How To Create A New Episerver Database 3

In your website, update your connection string to point to your new database, as shown above:

How To Create A New Episerver Database 4

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.

How To Create A New Episerver Database 5

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

How To Create A New Episerver Database 6

An XML file should now download to your computer:

How To Create A New Episerver Database 5

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 🤘