Valid TaskActions are:

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

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)

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)

SetOffline (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

SetOnline (Required: DatabaseItem Optional: NoPooling, StatementTimeout)

VerifyBackup (Required: DataFilePath Optional: NoPooling, StatementTimeout)

Remote Execution Support: Yes

Namespace: MSBuild.ExtensionPack.Sql2005
Assembly: MSBuild.ExtensionPack.Sql2005 (in MSBuild.ExtensionPack.Sql2005.dll) Version: 3.5.0.0

Examples

Xml Copy imageCopy
<Project ToolsVersion="3.5" 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>
        </ItemGroup>
        <!-- Get information on a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="GetInfo" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance">
            <Output TaskParameter="Information" ItemName="AllInfo"/>
        </MSBuild.ExtensionPack.Sql2005.Database>
        <!-- All the database information properties are available as metadata on the Infomation item -->
        <Message Text="SpaceAvailable: %(AllInfo.SpaceAvailable)"/>
        <!-- Backup a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Backup" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance" DataFilePath="c:\a\ADatabase2005.bak"/>
        <!-- Verify a database backup -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="VerifyBackup" DataFilePath="c:\a\ADatabase2005.bak" MachineName="MyServer\SQL2005Instance"/>
        <!-- Restore a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Restore" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance" DataFilePath="c:\a\ADatabase2005.bak"/>
        <!-- Create a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Create" DatabaseItem="ADatabase2" MachineName="MyServer\SQL2005Instance"/>
        <!-- Create the database again, using Force to delete the existing database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Create" DatabaseItem="ADatabase2" Force="true" Collation="Latin1_General_CI_AI" MachineName="MyServer\SQL2005Instance"/>
        <!-- Check whether a database exists -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="CheckExists" DatabaseItem="ADatabase2" MachineName="MyServer\SQL2005Instance">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Sql2005.Database>
        <Message Text="Database Exists: $(DoesExist)"/>
        <!-- Delete a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Delete" DatabaseItem="ADatabase2" MachineName="MyServer\SQL2005Instance"/>
        <!-- Check whether a database exists -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="CheckExists" DatabaseItem="ADatabase2" MachineName="MyServer\SQL2005Instance">
            <Output TaskParameter="Exists" PropertyName="DoesExist"/>
        </MSBuild.ExtensionPack.Sql2005.Database>
        <Message Text="Database Exists: $(DoesExist)"/>
        <!-- Get the number of active connections to a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="GetConnectionCount" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance">
            <Output TaskParameter="ConnectionCount" PropertyName="Count"/>
        </MSBuild.ExtensionPack.Sql2005.Database>
        <Message Text="Database ConnectionCount: $(Count)"/>
        <!-- Delete the backup history for a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="DeleteBackupHistory" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance"/>
        <!-- Set a database offline -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="SetOffline" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance"/>
        <!-- Set a database online -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="SetOnline" DatabaseItem="ADatabase" MachineName="MyServer\SQL2005Instance"/>
        <!-- Rename a database -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Rename" DatabaseItem="@(Database)" MachineName="MyServer\SQL2005Instance"/>
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Rename" DatabaseItem="@(Database2)" MachineName="MyServer\SQL2005Instance"/>
        <!-- Script a database to file -->
        <MSBuild.ExtensionPack.Sql2005.Database TaskAction="Script" DatabaseItem="ADatabase" OutputFilePath="c:\ADatabaseScript2005.sql" MachineName="MyServer\SQL2005Instance"/>
        <!-- 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>

Inheritance Hierarchy

System..::..Object
  Microsoft.Build.Utilities..::..Task
    MSBuild.ExtensionPack..::..BaseTask
      MSBuild.ExtensionPack.Sql2005..::..Database

See Also