Class DatabaseContext
The Umbraco Database context
Inheritance
Namespace:System.Dynamic.ExpandoObject
Assembly:Umbraco.Core.dll
Syntax
public class DatabaseContext
Remarks
One per AppDomain, represents the Umbraco database
Constructors
DatabaseContext(IDatabaseFactory)
Declaration
[Obsolete("Use the constructor specifying all dependencies instead")]
public DatabaseContext(IDatabaseFactory factory)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseFactory | factory |
DatabaseContext(IDatabaseFactory, ILogger, ISqlSyntaxProvider, String)
Create a configured DatabaseContext
Declaration
public DatabaseContext(IDatabaseFactory factory, ILogger logger, ISqlSyntaxProvider sqlSyntax, string providerName)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseFactory | factory | |
ILogger | logger | |
ISqlSyntaxProvider | sqlSyntax | |
System.String | providerName |
DatabaseContext(IDatabaseFactory, ILogger, SqlSyntaxProviders)
Default constructor
Declaration
public DatabaseContext(IDatabaseFactory factory, ILogger logger, SqlSyntaxProviders syntaxProviders)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseFactory | factory | |
ILogger | logger | |
SqlSyntaxProviders | syntaxProviders |
Properties
CanConnect
Determines if the db can be connected to
Declaration
public virtual bool CanConnect { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
ConnectionString
Gets the configured umbraco db connection string.
Declaration
public virtual string ConnectionString { get; }
Property Value
Type | Description |
---|---|
System.String |
Database
Gets an "ambient" database for doing CRUD operations against custom tables that resides in the Umbraco database.
Declaration
public virtual UmbracoDatabase Database { get; }
Property Value
Type | Description |
---|---|
UmbracoDatabase |
Remarks
Should not be used for operation against standard Umbraco tables; as services should be used instead.
Gets or creates an "ambient" database that is either stored in http context + available for the whole request + auto-disposed at the end of the request, or stored in call context if there is no http context - in which case it must be explicitely disposed (which will remove it from call context).
DatabaseProvider
Returns the Type of DatabaseProvider used
Declaration
public virtual DatabaseProviders DatabaseProvider { get; }
Property Value
Type | Description |
---|---|
DatabaseProviders |
IsDatabaseConfigured
Boolean indicating whether the database has been configured
Declaration
public virtual bool IsDatabaseConfigured { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
SqlSyntax
Declaration
public ISqlSyntaxProvider SqlSyntax { get; }
Property Value
Type | Description |
---|---|
ISqlSyntaxProvider |
Methods
ConfigureDatabaseConnection(String)
Configure a ConnectionString that has been entered manually.
Declaration
public void ConfigureDatabaseConnection(string connectionString)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionString |
Remarks
Please note that we currently assume that the 'System.Data.SqlClient' provider can be used.
ConfigureDatabaseConnection(String, String, String, String, String)
Configures a ConnectionString for the Umbraco database based on the passed in properties from the installer.
Declaration
public void ConfigureDatabaseConnection(string server, string databaseName, string user, string password, string databaseProvider)
Parameters
Type | Name | Description |
---|---|---|
System.String | server | Name or address of the database server |
System.String | databaseName | Name of the database |
System.String | user | Database Username |
System.String | password | Database Password |
System.String | databaseProvider | Type of the provider to be used (Sql, Sql Azure, Sql Ce, MySql) |
ConfigureEmbeddedDatabaseConnection()
Configure a ConnectionString for the embedded database.
Declaration
public void ConfigureEmbeddedDatabaseConnection()
ConfigureIntegratedSecurityDatabaseConnection(String, String)
Configures a ConnectionString for the Umbraco database that uses Microsoft SQL Server integrated security.
Declaration
public void ConfigureIntegratedSecurityDatabaseConnection(string server, string databaseName)
Parameters
Type | Name | Description |
---|---|---|
System.String | server | Name or address of the database server |
System.String | databaseName | Name of the database |
GetDatabaseConnectionString(String, String, String, String, String, out String)
Declaration
public string GetDatabaseConnectionString(string server, string databaseName, string user, string password, string databaseProvider, out string providerName)
Parameters
Type | Name | Description |
---|---|---|
System.String | server | |
System.String | databaseName | |
System.String | user | |
System.String | password | |
System.String | databaseProvider | |
System.String | providerName |
Returns
Type | Description |
---|---|
System.String |
GetEmbeddedDatabaseConnectionString()
Declaration
public string GetEmbeddedDatabaseConnectionString()
Returns
Type | Description |
---|---|
System.String |
GetIntegratedSecurityDatabaseConnectionString(String, String)
Declaration
public string GetIntegratedSecurityDatabaseConnectionString(string server, string databaseName)
Parameters
Type | Name | Description |
---|---|---|
System.String | server | |
System.String | databaseName |
Returns
Type | Description |
---|---|
System.String |