Database Class

MSBuild Extension Pack

Database Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

Attach (Required: DatabaseItem Optional: See notes on metadata for DatabaseItem)

Backup (Required: DatabaseItem, DataFilePath Optional: BackupAction, CompressionOption, Incremental, NotificationInterval, NoPooling, StatementTimeout, CopyOnly)

CheckExists (Required: DatabaseItem Optional: NoPooling, StatementTimeout Output: Exists)

Create (Required: DatabaseItem Optional: Collation, NoPooling, DataFilePath, LogName, LogFilePath, FileGroupName, StatementTimeout)

Delete (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

DeleteBackupHistory (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

Detach (Required: DatabaseItem Optional: See notes on metadata for DatabaseItem)

GetConnectionCount (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

GetInfo (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

Rename (Required: DatabaseItem (NewName metadata) Optional: NoPooling, StatementTimeout)

Restore (Required: DatabaseItem, DataFilePath Optional: ReplaceDatabase, NewDataFilePath, RestoreAction, Incremental, NotificationInterval, NoPooling, LogName, LogFilePath, PrimaryDataFileName, SecondaryDataFileName, SecondaryDataFilePath, StatementTimeout)

Script (Required: DatabaseItem, OutputFilePath Optional: NoPooling, StatementTimeout)

ScriptData (Required: DatabaseItem, OutputFilePath Optional: ScriptDrops, ScriptSchema, NoPooling, StatementTimeout)

SetOffline (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

SetOnline (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

VerifyBackup (Required: DataFilePath Optional: NoPooling, StatementTimeout)

Remote Execution Support: Yes

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.Sql2008Database

Namespace: MSBuild.ExtensionPack.Sql2008
Assembly: MSBuild.ExtensionPack.Sql2008 (in MSBuild.ExtensionPack.Sql2008.dll) Version: 4.0.0.0

The Database type exposes the following members.

Constructors

  NameDescription
Public methodDatabase
Top
Properties

  NameDescription
Public propertyBackupAction
Sets the type of backup action to perform. Supports Database, Files and Log. Default is Database
Public propertyCollation
Sets the collation of the database.
Public propertyCompressionOption
Sets the compression option for the backup. Supports On, Off and Default. Default is Default.
Public propertyConnectionCount
Gets the number of connections the database has open
Public propertyCopyOnly
Sets whether the backup is a copy-only backup. Default is false.
Public propertyDatabaseItem
Sets the database name. When using Attach, you can specify the following metadata: Owner, Files (semicolon delimited), AttachOptions (Default None). When using Detach, you can specify the following metadata: UpdateStatistics, RemoveFulltextIndexFile (both default to false).
Public propertyDataFilePath
Sets the DataFilePath.
Public propertyExists
Gets whether the database exists
Public propertyFileGroupName
Sets the FileGroupName. Defaults to PRIMARY
Public propertyForce
Set to true to force the creation of a database if it already exists.
Public propertyIncremental
Set to true to perform an Incremental backup. Default is false.
Public propertyInformation
Gets the Information TaskItem. Each available property is added as metadata.
Public propertyLogFilePath
Sets the LogFilePath.
Public propertyLogName
Sets the Log Name. Defaults DatabaseItem.ItemSpec + "_log"
Public propertyNewDataFilePath
Sets the NewDataFilePath.
Public propertyNoPooling
Set to true to create a NonPooledConnection to the server. Default is false.
Public propertyNotificationInterval
Sets the PercentCompleteNotification interval. Defaults to 10.
Public propertyOutputFilePath
Sets the OutputFilePath.
Public propertyPrimaryDataFileName
Sets the primary data file name.
Public propertyRegexPattern
Sets the regex pattern.
Public propertyReplaceDatabase
A Boolean value that specifies whether a new image of the restored database will be created. If True, a new image of the database is created. The image is created regardless of the presence of an existing database with the same name. If False (default), a new image of the database is not created by the restore operation. The database targeted by the restore operation must exist on an instance of Microsoft SQL Server.
Public propertyRestoreAction
Sets the type of restore action to perform. Supports Database, Files, Log, OnlineFiles, OnlinePage. Default is Database
Public propertyScriptDrops
Sets ScriptingOptions for ScriptData TaskAction
Public propertyScriptSchema
Sets ScriptingOptions for ScriptData TaskAction
Public propertySecondaryDataFileName
Sets the secondary data file name. No default value.
Public propertySecondaryDataFilePath
Sets the SecondaryDataFilePath.
Public propertyStatementTimeout
Sets the number of seconds before an operation times out. The default is not to specify this property on the connection.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <ItemGroup>
            <Database Include="ADatabase">
                <NewName>ADatabase2</NewName>
            </Database>
            <Database2 Include="ADatabase2">
                <NewName>ADatabase</NewName>
            </Database2>
            <Database3 Include="ADatabase3">
                <Owner></Owner>
                <AttachOptions>1</AttachOptions>
                <UpdateStatistics>true</UpdateStatistics>
                <RemoveFulltextIndexFile>true</RemoveFulltextIndexFile>
                <Files>C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\ADatabase3.mdf;C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\ADatabase3_log.LDF</Files>
            </Database3>
        </ItemGroup>
        <!-- Create Database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Delete" DatabaseItem="@(Database3)" ContinueOnError="true"/>
        <!-- Create Database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Create" DatabaseItem="@(Database3)"/>
        <!-- Detach Database-->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Detach" DatabaseItem="@(Database3)"/>
        <!-- Attach Database-->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Attach" DatabaseItem="@(Database3)"/>
        <!-- Get information on a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="GetInfo" DatabaseItem="ADatabase">
            <Output TaskParameter="Information" ItemName="AllInfo"/>
        </MSBuild.ExtensionPack.Sql2008.Database>
        <!-- All the database information properties are available as metadata on the Infomation item -->
        <Message Text="SpaceAvailable: %(AllInfo.SpaceAvailable)"/>
        <!-- ScriptData for tables matching Acc* name -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="ScriptData" RegexPattern="Acc*" DatabaseItem="ADatabase" OutputFilePath="c:\ADatabase.sql"/>
        <!-- Backup a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Backup" DatabaseItem="ADatabase" DataFilePath="c:\a\ADatabase.bak"/>
        <!-- Verify a database backup -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" DataFilePath="c:\a\ADatabase.bak"/>
        <!-- Restore a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Restore" DatabaseItem="ADatabase" DataFilePath="c:\a\ADatabase.bak"/>
        <!-- Restore a database to a different location-->
        <MSBuild.ExtensionPack.Sql2008.Database MachineName="Desktop\SQL2008" TaskAction="Restore" DatabaseItem="ADatabase" DataFilePath="c:\a\ADatabase.bak" NewDataFilePath="c:\k\ADatabase2.mdf" LogFilePath="c:\a\ADatabase2_log.LDF"/>
        <!-- Create a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Create" DatabaseItem="ADatabase2"/>
        <!-- Create the database again, using Force to delete the existing database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Create" DatabaseItem="ADatabase2" Collation="Latin1_General_CI_AI" Force="true"/>
        <!-- Check whether a database exists -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="CheckExists" DatabaseItem="ADatabase2">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Sql2008.Database>
        <Message Text="Database Exists: $(DoesExist)"/>
        <!-- Delete a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Delete" DatabaseItem="ADatabase2"/>
        <!-- Check whether a database exists -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="CheckExists" DatabaseItem="ADatabase2">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Sql2008.Database>
        <Message Text="Database Exists: $(DoesExist)"/>
        <!-- Get the number of active connections to a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="GetConnectionCount" DatabaseItem="ADatabase">
            <Output TaskParameter="ConnectionCount" PropertyName="Count"/>
        </MSBuild.ExtensionPack.Sql2008.Database>
        <Message Text="Database ConnectionCount: $(Count)"/>
        <!-- Delete the backup history for a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="DeleteBackupHistory" DatabaseItem="ADatabase"/>
        <!-- Set a database offline -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="SetOffline" DatabaseItem="ADatabase"/>
        <!-- Set a database online -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="SetOnline" DatabaseItem="ADatabase"/>
        <!-- Rename a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Rename" DatabaseItem="@(Database)"/>
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Rename" DatabaseItem="@(Database2)"/>
        <!-- Script a database to file -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Script" DatabaseItem="ReportServer" OutputFilePath="c:\ADatabaseScript.sql"/>
        <!-- Restore a database to a new Name -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Restore" MachineName="$(SqlServerName)" DatabaseItem="$(DatabaseName)" DataFilePath="$(DbDataFilePath)" PrimaryDataFileName="SomeDatabase" LogName="SomeDatabase_log" SecondaryDataFileName="SomeDatabase_CDC" NewDataFilePath="$(OSFilePath)$(DatabaseName).mdf" SecondaryDataFilePath="$(OSFilePath)$(DatabaseName)_CDC.ndf" LogFilePath="$(OSFilePath)\$(DatabaseName)_log.ldf" ReplaceDatabase="True" />
    </Target>
</Project>
See Also

Reference