SqlServer aliases

Cake.SqlServer addin

Contains functionality to deal with SQL Server: DropDatabase, CreateDatabase, execute SQL, execute SQL from files, etc. Provides functionality to manage LocalDb instances: Create, Start, Stop, Delete instances;

In order to use the commands for this addin, include the following in your build.cake file to download and reference from NuGet.org:

#addin "nuget:?package=Cake.SqlServer"

General

BackupDatabase(ICakeContext, string, string, BackupDatabaseSettings)
Alias from Cake.SqlServer addin
Backup an existing database to a file.
CreateBacpacFile(ICakeContext, string, string, FilePath)
Alias from Cake.SqlServer addin
Creates a bacpac file for easy database backuping.
CreateDatabase(ICakeContext, string, string)
Alias from Cake.SqlServer addin
Creates an empty database. If database with this name already exists, throws a SqlException. Cake.SqlServer.SqlServerAliases.CreateDatabaseIfNotExists(Cake.Core.ICakeContext,System.String,System.String) if you would like to check if database already exists.
CreateDatabase(ICakeContext, string, string, CreateDatabaseSettings)
Alias from Cake.SqlServer addin
Creates an empty database. If database with this name already exists, throws a SqlException. Allows to specify primary and log files location.
CreateDatabaseIfNotExists(ICakeContext, string, string)
Alias from Cake.SqlServer addin
Creates an empty database if another database with the same does not already exist.
CreateDatabaseIfNotExists(ICakeContext, string, string, CreateDatabaseSettings)
Alias from Cake.SqlServer addin
Creates an empty database if another database with the same does not already exist.
DatabaseExists(ICakeContext, string, string)
Alias from Cake.SqlServer addin
Test if the database exists
DropAndCreateDatabase(ICakeContext, string, string)
Alias from Cake.SqlServer addin
First drops, then recreates the database
DropAndCreateDatabase(ICakeContext, string, string, CreateDatabaseSettings)
Alias from Cake.SqlServer addin
First drops, then recreates the database
DropDatabase(ICakeContext, string, string)
Alias from Cake.SqlServer addin
Drops database. Before dropping the DB, database is set to be offline, then online again. This is to be sure that there are no live connections, otherwise the script will fail. Also if the database does not exist - it will not do anything.
ExecuteSqlCommand(ICakeContext, SqlConnection, string)
Alias from Cake.SqlServer addin
Execute any SQL command.
ExecuteSqlCommand(ICakeContext, string, string)
Alias from Cake.SqlServer addin
Execute any SQL command.
ExecuteSqlFile(ICakeContext, SqlConnection, FilePath)
Alias from Cake.SqlServer addin
Reads SQL commands from a file and executes them.
ExecuteSqlFile(ICakeContext, string, FilePath)
Alias from Cake.SqlServer addin
Reads SQL commands from a file and executes them.
ExtractDacpacFile(ICakeContext, string, string, ExtractDacpacSettings)
Alias from Cake.SqlServer addin
Extracts a dacpac file to a database package.
LocalDbCreateInstance(ICakeContext, string)
Alias from Cake.SqlServer addin
Creates a server instance and starts the server. The version number defaults to the version of the SqlLocalDB utility
LocalDbCreateInstance(ICakeContext, string, LocalDbVersion)
Alias from Cake.SqlServer addin
Creates a server instance and starts the server.
LocalDbDeleteInstance(ICakeContext, string)
Alias from Cake.SqlServer addin
Deletes the LocalDB instance
LocalDbStartInstance(ICakeContext, string)
Alias from Cake.SqlServer addin
Starts the LocalDB instance. Instance must exist before you can start it.
LocalDbStopInstance(ICakeContext, string)
Alias from Cake.SqlServer addin
Stops the LocalDB instance.
OpenSqlConnection(ICakeContext, string)
Alias from Cake.SqlServer addin
Opens a new System.Data.SqlClient.SqlConnection with the given connection string.
PublishDacpacFile(ICakeContext, string, string, FilePath, PublishDacpacSettings)
Alias from Cake.SqlServer addin
Publish a dacpac file to a database.
RestoreBacpac(ICakeContext, string, string, FilePath)
Alias from Cake.SqlServer addin
Restores a bacpac file into a database.

NB: there must be no database with the name you provide. Otherwise exception will be thrown.

RestoreMultipleSqlBackup(ICakeContext, string, RestoreSqlBackupSettings, IList<FilePath>, IList<FilePath>)
Alias from Cake.SqlServer addin
Restores a database from multiple backup files.
RestoreSqlBackup(ICakeContext, string, FilePath)
Alias from Cake.SqlServer addin
Restores a database from a backup file.
RestoreSqlBackup(ICakeContext, string, FilePath, RestoreSqlBackupSettings)
Alias from Cake.SqlServer addin
Restores a database from a backup file.
SetSqlCommandTimeout(ICakeContext, int)
Alias from Cake.SqlServer addin
Sets the CommandTimeout property for all SqlCommands used internally