Class DatabaseBuilder
Supports building and configuring the database.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Migrations.Install
Assembly: cs.temp.dll.dll
Syntax
public class DatabaseBuilder
Constructors
DatabaseBuilder(IScopeProvider, IUmbracoDatabaseFactory, IRuntimeState, ILoggerFactory, IKeyValueService, IDbProviderFactoryCreator, IConfigManipulator, IOptionsMonitor<GlobalSettings>, IOptionsMonitor<ConnectionStrings>, IMigrationPlanExecutor, DatabaseSchemaCreatorFactory)
Initializes a new instance of the DatabaseBuilder class.
Declaration
public DatabaseBuilder(IScopeProvider scopeProvider, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtimeState, ILoggerFactory loggerFactory, IKeyValueService keyValueService, IDbProviderFactoryCreator dbProviderFactoryCreator, IConfigManipulator configManipulator, IOptionsMonitor<GlobalSettings> globalSettings, IOptionsMonitor<ConnectionStrings> connectionStrings, IMigrationPlanExecutor migrationPlanExecutor, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| IScopeProvider | scopeProvider | |
| IUmbracoDatabaseFactory | databaseFactory | |
| IRuntimeState | runtimeState | |
| ILoggerFactory | loggerFactory | |
| IKeyValueService | keyValueService | |
| IDbProviderFactoryCreator | dbProviderFactoryCreator | |
| IConfigManipulator | configManipulator | |
| IOptionsMonitor<GlobalSettings> | globalSettings | |
| IOptionsMonitor<ConnectionStrings> | connectionStrings | |
| IMigrationPlanExecutor | migrationPlanExecutor | |
| DatabaseSchemaCreatorFactory | databaseSchemaCreatorFactory |
Fields
EmbeddedDatabaseConnectionString
Declaration
public const string EmbeddedDatabaseConnectionString = "Data Source=|DataDirectory|\\Umbraco.sdf;Flush Interval=1"
Field Value
| Type | Description |
|---|---|
| System.String |
LocalDbConnectionString
Declaration
public const string LocalDbConnectionString = "Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Umbraco.mdf;Integrated Security=True"
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
CanConnectToDatabase
Gets a value indicating whether it is possible to connect to the configured database. It does not necessarily mean that Umbraco is installed, nor up-to-date.
Declaration
public bool CanConnectToDatabase { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsDatabaseConfigured
Gets a value indicating whether the database is configured. It does not necessarily mean that it is possible to connect, nor that Umbraco is installed, nor up-to-date.
Declaration
public bool IsDatabaseConfigured { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
CanConnect(String, String, String, String, String, String, Boolean)
Verifies whether a it is possible to connect to a database.
Declaration
public bool CanConnect(string databaseType, string connectionString, string server, string database, string login, string password, bool integratedAuth)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseType | |
| System.String | connectionString | |
| System.String | server | |
| System.String | database | |
| System.String | login | |
| System.String | password | |
| System.Boolean | integratedAuth |
Returns
| Type | Description |
|---|---|
| System.Boolean |
ConfigureDatabaseConnection(String)
Configures a connection string that has been entered manually.
Declaration
public void ConfigureDatabaseConnection(string connectionString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | connectionString | A connection string. |
Remarks
Has to be SQL Server
ConfigureDatabaseConnection(String, String, String, String, String)
Configures a connection string from the installer.
Declaration
public void ConfigureDatabaseConnection(string server, string databaseName, string user, string password, string databaseProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | server | The name or address of the database server. |
| System.String | databaseName | The name of the database. |
| System.String | user | The user name. |
| System.String | password | The user password. |
| System.String | databaseProvider | The name of the provider (Sql, Sql Azure, Sql Ce). |
ConfigureEmbeddedDatabaseConnection()
Configures a connection string for the embedded database.
Declaration
public void ConfigureEmbeddedDatabaseConnection()
ConfigureIntegratedSecurityDatabaseConnection(String, String)
Configures a connection string using Microsoft SQL Server integrated security.
Declaration
public void ConfigureIntegratedSecurityDatabaseConnection(string server, string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | server | The name or address of the database server. |
| System.String | databaseName | The name of the database |
ConfigureSqlLocalDbDatabaseConnection()
Declaration
public void ConfigureSqlLocalDbDatabaseConnection()
CreateDatabase()
Declaration
public void CreateDatabase()
CreateSchemaAndData()
Creates the database schema and inserts initial data.
Declaration
public DatabaseBuilder.Result CreateSchemaAndData()
Returns
| Type | Description |
|---|---|
| DatabaseBuilder.Result |
Remarks
This assumes that the database exists and the connection string is configured and it is possible to connect to the database.
GetAzureConnectionString(String, String, String, String)
Gets an Azure connection string.
Declaration
public static string GetAzureConnectionString(string server, string databaseName, string user, string password)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | server | The name or address of the database server. |
| System.String | databaseName | The name of the database. |
| System.String | user | The user name. |
| System.String | password | The user password. |
Returns
| Type | Description |
|---|---|
| System.String | A connection string. |
GetDatabaseConnectionString(String, String, String, String, String, out String)
Gets a connection string from the installer.
Declaration
public static string GetDatabaseConnectionString(string server, string databaseName, string user, string password, string databaseProvider, out string providerName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | server | The name or address of the database server. |
| System.String | databaseName | The name of the database. |
| System.String | user | The user name. |
| System.String | password | The user password. |
| System.String | databaseProvider | The name of the provider (Sql, Sql Azure, Sql Ce). |
| System.String | providerName |
Returns
| Type | Description |
|---|---|
| System.String | A connection string. |
GetIntegratedSecurityDatabaseConnectionString(String, String)
Gets a connection string using Microsoft SQL Server integrated security.
Declaration
public static string GetIntegratedSecurityDatabaseConnectionString(string server, string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | server | The name or address of the database server. |
| System.String | databaseName | The name of the database |
Returns
| Type | Description |
|---|---|
| System.String | A connection string. |
HasSomeNonDefaultUser()
Declaration
public bool HasSomeNonDefaultUser()
Returns
| Type | Description |
|---|---|
| System.Boolean |
UpgradeSchemaAndData(UmbracoPlan)
Upgrades the database schema and data by running migrations.
Declaration
public DatabaseBuilder.Result UpgradeSchemaAndData(UmbracoPlan plan)
Parameters
| Type | Name | Description |
|---|---|---|
| UmbracoPlan | plan |
Returns
| Type | Description |
|---|---|
| DatabaseBuilder.Result |
Remarks
This assumes that the database exists and the connection string is configured and it is possible to connect to the database.
Runs whichever migrations need to run.
ValidateSchema()
Validates the database schema.
Declaration
public DatabaseSchemaResult ValidateSchema()
Returns
| Type | Description |
|---|---|
| DatabaseSchemaResult |
Remarks
This assumes that the database exists and the connection string is configured and it is possible to connect to the database.