As developers, we often want to experiment and tinker around with our website, one side effect of this is that databases tend to end up corrupting the database, or, wanting to start from scratch.  Luckily, with Umbraco, this is very easy and in today’s tutorial, I’m going to go over the process to create a clean Umbraco database.

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.  Open MS-SQL manager and create a new database, by right-clicking on your database instance and selecting ‘New Database’!  Give your database a name and a database owner.  The next step is to clear your web.config out.  First, we need to clear out the connection string.

  <connectionStrings>
    <remove name="umbracoDbDSN" />
    <add name="umbracoDbDSN" connectionString="" providerName="" />
  </connectionStrings>

Remember, if you do not do this you will likely see this error message, ‘Invalid object name’ When you have a connection string set in your web.config, the installer assumes that the database is already set up and instead of trying to install something, it tries to log you in and fails. The last part of the pre-clean configuration, is to clear out the umbracoConfigurationStatus.

  <appSettings>
    <add key="umbracoConfigurationStatus" value="" />
  </appSettings>

In your appSettings, find umbracoConfigurationStatus and clear it. Now, we should be able to rerun the installer and create a new database. Load your website and put /install at the end, like so, www.website.com/install, this should now load the Umbraco set-up page. 

Tips When Rebuilding Your Database

When you reset your database and clear your database down, it’s likely third-party packages might blow-up and prevent the installer from loading.  I was using uSiteBuilder in my project and as soon as I cleared my database, it threw several exceptions, like ‘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.ascx.

        void Application_Error(object sender, EventArgs e)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(object));
            log.Fatal("Unhandled Exception", Server.GetLastError());

            Server.ClearError();
        }

In your global.ascx file you can then add this method which will clear all unhandled exceptions and allow the installer to run.

Rate this post