Search Results for

    Show / Hide Table of Contents
    View Source

    Class LocalDb

    Manages LocalDB databases.

    Inheritance
    System.Object
    Namespace: Umbraco.Cms.Persistence.SqlServer
    Assembly: Umbraco.Cms.Persistence.SqlServer.dll
    Syntax
    public class LocalDb
    Remarks

    Latest version is SQL Server 2016 Express LocalDB, see https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-2016-express-localdb which can be installed by downloading the Express installer from https://www.microsoft.com/en-us/sql-server/sql-server-downloads (about 5MB) then select 'download media' to download SqlLocalDB.msi (about 44MB), which you can execute. This installs LocalDB only. Though you probably want to install the full Express. You may also want to install SQL Server Management Studio which can be used to connect to LocalDB databases.

    See also https://github.com/ritterim/automation-sql which is a somewhat simpler version of this.

    Properties

    View Source

    IsAvailable

    Gets a value indicating whether LocalDb is available.

    Declaration
    public bool IsAvailable { get; }
    Property Value
    Type Description
    System.Boolean
    View Source

    Version

    Gets the LocalDb installed version.

    Declaration
    public int Version { get; }
    Property Value
    Type Description
    System.Int32
    Remarks

    If more than one version is installed, returns the highest available. Returns the major version as an integer e.g. 11, 12...

    Methods

    View Source

    CopyDatabaseFiles(String, String, String, String, String, String, Boolean, Boolean)

    Copy database files.

    Declaration
    public void CopyDatabaseFiles(string databaseName, string filesPath, string targetDatabaseName = null, string targetFilesPath = null, string sourceExtension = null, string targetExtension = null, bool overwrite = false, bool delete = false)
    Parameters
    Type Name Description
    System.String databaseName

    The name of the source database.

    System.String filesPath

    The directory containing source database files.

    System.String targetDatabaseName

    The name of the target database.

    System.String targetFilesPath

    The directory containing target database files.

    System.String sourceExtension

    The source database files extension.

    System.String targetExtension

    The target database files extension.

    System.Boolean overwrite

    A value indicating whether to overwrite the target files.

    System.Boolean delete

    A value indicating whether to delete the source files.

    Remarks

    The targetDatabaseName, targetFilesPath, sourceExtension and targetExtension parameters are optional. If they result in target being identical to source, no copy is performed. If delete is false, nothing happens, otherwise the source files are deleted. If target is not identical to source, files are copied or moved, depending on the value of delete. Extensions are used eg to copy MyDatabase.mdf to MyDatabase.mdf.temp.

    View Source

    CreateInstance(String)

    Creates a LocalDb instance.

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

    The name of the instance.

    Returns
    Type Description
    System.Boolean

    A value indicating whether the instance was created without errors.

    View Source

    DatabaseFilesExist(String, String, String)

    Gets a value indicating whether database files exist.

    Declaration
    public bool DatabaseFilesExist(string databaseName, string filesPath, string extension = null)
    Parameters
    Type Name Description
    System.String databaseName

    The name of the source database.

    System.String filesPath

    The directory containing source database files.

    System.String extension

    The database files extension.

    Returns
    Type Description
    System.Boolean

    A value indicating whether the database files exist.

    Remarks

    Extensions are used eg to copy MyDatabase.mdf to MyDatabase.mdf.temp.

    View Source

    DropInstance(String)

    Drops a LocalDb instance.

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

    The name of the instance.

    Returns
    Type Description
    System.Boolean

    A value indicating whether the instance was dropped without errors.

    Remarks

    When an instance is dropped all the attached database files are deleted. Successful if the instance does not exist.

    View Source

    GetInstance(String)

    Gets a LocalDb instance.

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

    The name of the instance.

    Returns
    Type Description
    LocalDb.Instance

    The instance with the specified name if it exists, otherwise null.

    View Source

    GetInstances()

    Gets the name of existing LocalDb instances.

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

    The name of existing LocalDb instances.

    View Source

    InstanceExists(String)

    Gets a value indicating whether a LocalDb instance exists.

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

    The name of the instance.

    Returns
    Type Description
    System.Boolean

    A value indicating whether a LocalDb instance with the specified name exists.

    View Source

    StartInstance(String)

    Stops a LocalDb instance.

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

    The name of the instance.

    Returns
    Type Description
    System.Boolean

    A value indicating whether the instance was started without errors.

    Remarks

    Failed if the instance does not exist.

    View Source

    StopInstance(String)

    Stops a LocalDb instance.

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

    The name of the instance.

    Returns
    Type Description
    System.Boolean

    A value indicating whether the instance was stopped without errors.

    Remarks

    Successful if the instance does not exist.

    • Improve this Doc
    • View Source
    In This Article
    • Properties
      • IsAvailable
      • Version
    • Methods
      • CopyDatabaseFiles(String, String, String, String, String, String, Boolean, Boolean)
      • CreateInstance(String)
      • DatabaseFilesExist(String, String, String)
      • DropInstance(String)
      • GetInstance(String)
      • GetInstances()
      • InstanceExists(String)
      • StartInstance(String)
      • StopInstance(String)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX