Search Results for

    Show / Hide Table of Contents
    View Source

    Class LocalDb.Instance

    Represents a LocalDb instance.

    Inheritance
    System.Object
    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 Source

    Instance(String)

    Initializes a new instance of the LocalDb.Instance class.

    Declaration
    public Instance(string instanceName)
    Parameters
    Type Name Description
    System.String instanceName

    Properties

    View Source

    InstanceName

    Gets the name of the instance.

    Declaration
    public string InstanceName { get; }
    Property Value
    Type Description
    System.String

    Methods

    View Source

    AttachDatabase(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.

    View Source

    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.

    View Source

    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.

    View Source

    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.

    View Source

    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.

    View Source

    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.

    View Source

    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.

    View Source

    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.

    View Source

    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.

    View Source

    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
    View Source

    GetDatabases()

    Gets the name of existing databases.

    Declaration
    public string[] GetDatabases()
    Returns
    Type Description
    System.String[]

    The name of existing databases.

    View Source

    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.

    View Source

    KillConnections(String)

    Kills all existing connections.

    Declaration
    public void KillConnections(string databaseName)
    Parameters
    Type Name Description
    System.String databaseName

    The name of the database.

    • Improve this Doc
    • View Source
    In This Article
    • Constructors
      • Instance(String)
    • Properties
      • InstanceName
    • Methods
      • AttachDatabase(String, String)
      • CreateDatabase(String, String)
      • DatabaseExists(String)
      • DetachDatabase(String)
      • DropDatabase(String)
      • DropDatabases(Boolean)
      • DropStaleDatabases()
      • GetAttachedConnectionString(String, String)
      • GetConnectionString(String)
      • GetConnectionString(String, String)
      • GetDatabases()
      • GetFilenames(String, out String, out String, out String, out String)
      • KillConnections(String)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX