In this tutorial, you will learn how to quickly create a clean Umbraco database. As developers, we often want to experiment and tinker around with our website. One negative side effect of messing around with a site is that the CMS database can end up corrupted. If you have an import script, creating a clean database and re-importing your content can be much quicker compared to figuring out what you have broken in your existing database and fixing it. Luckily, with Umbraco, it is very easy to create a new database and import content. In this tutorial, I will show you everything you need to know so you can do the same 🔥🔥🔥.

Creating A Clean Umbraco Database

The first thing you need to do is to delete your existing Umbraco database and create a new empty database:

How To Create A Clean Umbraco Database 1

Open MS-SQL manager (SSMS) and create a new database. You can do this by right-clicking on your database instance and selecting New Database:

How To Create A Clean Umbraco Database 2

Give your database a new name and set the database owner with an account you know the username and password for. Remember, you need to set your SQL authentication mode as mixed mode to allow for a username and password to be used within your connection string. The next step is to clear your web.config out. First, we need to clear out the connection string:

If you do not follow this step, you will likely see this error message, Invalid object name. The reason for this error is because when a connection string is set in the web.config, the Umbraco installer assumes that the database is already set up. Instead of trying to install the new CMS tables, it tries to log you into the existing database to upgrade it instead. This will cause the installer to fail, so when going from scratch delete any data in the connectionString. The last step of the clean-up process involves a setting in appSettings. You will need to empty out the value in the umbracoConfigurationStatus setting:

Find this value in appSettings, find umbracoConfigurationStatus and clear it. You can now rerun the installer and create a new database. Load your website and put /install at the end of the URL, e.g., this should now load the Umbraco installer:

How To Create A Clean Umbraco Database 3

Tips When Rebuilding Your Database

When you clear your database down, it's likely third-party packages might blow up and prevent the installer from successfully completing. For example, I was using uSiteBuilder on one project. As soon as I cleared my database, and tried to run the installer, I encountered this exception:

Value cannot be null. Parameter name: sqlSyntax

To get around this issue, you can force Umbraco to mask all unhandled exceptions. First, if you haven't already, you need to enable code to be run within your global.asax.

In the global.asax, you can then add this code into the Application_Error method which will clear all unhandled exceptions and allow the installer to run. I do not recommend keeping this line in forever, however, it will allow you to upgrade quickly and painfree. With a fresh install, you can now re-import content and get back to a lovely clean state. Happy Coding 🤘