Skip to content

Enable ForceCreateDatabase for SqlServer#14234

Merged
nikolajlauridsen merged 1 commit intov11/devfrom
v11/bugfix/enable-forcecreate-for-SqlServer
May 11, 2023
Merged

Enable ForceCreateDatabase for SqlServer#14234
nikolajlauridsen merged 1 commit intov11/devfrom
v11/bugfix/enable-forcecreate-for-SqlServer

Conversation

@Zeegaan
Copy link
Copy Markdown
Member

@Zeegaan Zeegaan commented May 11, 2023

Fixes #14110

Notes

  • Enable ForceCreateDatabase for SqlServerDatabaseProviderMetadata

How to test

  • Set your connectionString in your AppSettings.json, I used my localDb like so:
    (If you do not have a SQL server running, create one first)
    Note here that although your server should be running, whatever database you set should not, so here my test database does not exist
  "ConnectionStrings": {
    "umbracoDbDSN": "Server=(localdb)\\MSSQLLocalDB;Database=test;Integrated Security=true",
    "umbracoDbDSN_ProviderName": "Microsoft.Data.SqlClient"
  },
  • Enable UnattendedInstall by setting in your AppSettings.Json, in the Umbraco/CMS section
      "Unattended": {
        "InstallUnattended": true,
        "UnattendedUserName": "Nikolaj Geisle",
        "UnattendedUserEmail": "{YOUR EMAIL HERE}",
        "UnattendedUserPassword": "{YOUR PASSWORD HERE}"
      },
  • Run Umbraco and assert that the database gets created, and thus umbraco gets installed and runs 👍

Copy link
Copy Markdown
Contributor

@nikolajlauridsen nikolajlauridsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nikolajlauridsen nikolajlauridsen merged commit 8d4e55f into v11/dev May 11, 2023
@nikolajlauridsen nikolajlauridsen deleted the v11/bugfix/enable-forcecreate-for-SqlServer branch May 11, 2023 12:39
@ronaldbarendse
Copy link
Copy Markdown
Contributor

We should revert this PR as soon as possible, because this change will now create a new SQL Server database even when InstallMissingDatabase is not enabled, see: https://docs.umbraco.com/umbraco-cms/fundamentals/setup/install/unattended-install#configure-your-database.

An incorrectly configured SQL Server connection string should throw a BootFailedException (by default) and not try to create a new database, install an empty Umbraco installation and thereby 'successfully' boot (but without the contents you expected):

if (_globalSettings.Value.InstallMissingDatabase || _databaseProviderMetadata.CanForceCreateDatabase(_databaseFactory))
{
// ok to install on a configured but missing database
Level = RuntimeLevel.Install;
Reason = RuntimeLevelReason.InstallMissingDatabase;
return;
}
// else it is bad enough that we want to throw
Reason = RuntimeLevelReason.BootFailedCannotConnectToDatabase;
BootFailedException = new BootFailedException("A connection string is configured but Umbraco could not connect to the database.");
throw BootFailedException;

The ForceCreateDatabase is enabled for SQL Server LocalDB and SQLite, because those should be used for local development and we want to make that a seamless experience. For production sites, we expect the connection string to be configured to an already existing database and quickly fail otherwise (or explicitly configure InstallMissingDatabase).

ronaldbarendse added a commit that referenced this pull request Jul 7, 2023
kjac added a commit that referenced this pull request Nov 22, 2024
Zeegaan pushed a commit that referenced this pull request Nov 26, 2024
…7612)

* Revert #14234

* Make the boot failure message more descriptive when unable to connect to DB

* Update src/Umbraco.Infrastructure/Runtime/RuntimeState.cs

Co-authored-by: Ronald Barendse <ronald@barend.se>

* Revert changes

* Obsolete InstallMissingDatabase from V16

---------

Co-authored-by: Ronald Barendse <ronald@barend.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants