Class LocalDb.Instance
Represents a LocalDb instance.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Persistence
Assembly: Umbraco.Infrastructure.dll
Syntax
public class Instance
Remarks
LocalDb is assumed to be available, and the instance is assumed to exist.
Constructors
View SourceInstance(String)
Initializes a new instance of the LocalDb.Instance class.
Declaration
public Instance(string instanceName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | instanceName |
Properties
View SourceInstanceName
Gets the name of the instance.
Declaration
public string InstanceName { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Methods
View SourceAttachDatabase(String, String)
Attaches a database.
Declaration
public void AttachDatabase(string databaseName, string filesPath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
| System.String | filesPath | The directory containing database files. |
CreateDatabase(String, String)
Creates a new database.
Declaration
public bool CreateDatabase(string databaseName, string filesPath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
| System.String | filesPath | The directory containing database files. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value indicating whether the database was created without errors. |
Remarks
Failed if a database with the specified name already exists in the instance, or if the database files already exist in the specified directory.
DatabaseExists(String)
Gets a value indicating whether a database exists.
Declaration
public bool DatabaseExists(string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value indicating whether a database with the specified name exists. |
Remarks
A database exists if it is registered in the instance, and its files exist. If the database is registered but some of its files are missing, the database is dropped.
DetachDatabase(String)
Detaches a database.
Declaration
public string DetachDatabase(string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
Returns
| Type | Description |
|---|---|
| System.String | The directory containing the database files. |
DropDatabase(String)
Drops a database.
Declaration
public bool DropDatabase(string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
Returns
| Type | Description |
|---|---|
| System.Boolean | A value indicating whether the database was dropped without errors. |
Remarks
Successful if the database does not exist. Deletes the database files.
DropDatabases(Boolean)
Drops databases.
Declaration
public int DropDatabases(bool staleOnly = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | staleOnly | A value indicating whether to delete only stale database. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of databases that were dropped. |
Remarks
A database is considered stale when its files cannot be found.
DropStaleDatabases()
Drops stale databases.
Declaration
public int DropStaleDatabases()
Returns
| Type | Description |
|---|---|
| System.Int32 | The number of databases that were dropped. |
Remarks
A database is considered stale when its files cannot be found.
GetAttachedConnectionString(String, String)
Gets a LocalDb connection string for an attached database.
Declaration
public string GetAttachedConnectionString(string databaseName, string filesPath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
| System.String | filesPath | The directory containing database files. |
Returns
| Type | Description |
|---|---|
| System.String | The connection string for the specified database. |
Remarks
The database should not exist in the LocalDb instance. It will be attached with its name being its MDF filename (full path), uppercased, when the first connection is opened, and remain attached until explicitly detached.
GetConnectionString(String)
Gets a LocalDb connection string.
Declaration
public string GetConnectionString(string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
Returns
| Type | Description |
|---|---|
| System.String | The connection string for the specified database. |
Remarks
The database should exist in the LocalDb instance.
GetConnectionString(String, String)
Declaration
public static string GetConnectionString(string instanceName, string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | instanceName | |
| System.String | databaseName |
Returns
| Type | Description |
|---|---|
| System.String |
GetDatabases()
Gets the name of existing databases.
Declaration
public string[] GetDatabases()
Returns
| Type | Description |
|---|---|
| System.String[] | The name of existing databases. |
GetFilenames(String, out String, out String, out String, out String)
Gets the file names of a database.
Declaration
public void GetFilenames(string databaseName, out string mdfName, out string ldfName, out string mdfFilename, out string ldfFilename)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |
| System.String | mdfName | The MDF logical name. |
| System.String | ldfName | The LDF logical name. |
| System.String | mdfFilename | The MDF filename. |
| System.String | ldfFilename | The LDF filename. |
KillConnections(String)
Kills all existing connections.
Declaration
public void KillConnections(string databaseName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | databaseName | The name of the database. |