SqlServer

Summary

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

CreateBacpacFile(ICakeContext, string, string, FilePath) Creates a bacpac file for easy database backuping.
Addin from Cake.SqlServer.dll
CreateDatabase(ICakeContext, string, string) 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.
Addin from Cake.SqlServer.dll
CreateDatabaseIfNotExists(ICakeContext, string, string) Creates an empty database if another database with the same does not already exist.
Addin from Cake.SqlServer.dll
DropAndCreateDatabase(ICakeContext, string, string) First drops, then recreates the database
Addin from Cake.SqlServer.dll
DropDatabase(ICakeContext, string, string) 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.
Addin from Cake.SqlServer.dll
ExecuteSqlCommand(ICakeContext, SqlConnection, string) Execute any SQL command.
Addin from Cake.SqlServer.dll
ExecuteSqlCommand(ICakeContext, string, string) Execute any SQL command.
Addin from Cake.SqlServer.dll
ExecuteSqlFile(ICakeContext, SqlConnection, FilePath) Reads SQL commands from a file and executes them.
Addin from Cake.SqlServer.dll
ExecuteSqlFile(ICakeContext, string, FilePath) Reads SQL commands from a file and executes them.
Addin from Cake.SqlServer.dll
ExtractDacpacFile(ICakeContext, string, string, ExtractDacpacSettings) Extracts a dacpac file to a database package.
Addin from Cake.SqlServer.dll
LocalDbCreateInstance(ICakeContext, string) Creates a server instance and starts the server. The version number defaults to the version of the SqlLocalDB utility
Addin from Cake.SqlServer.dll
LocalDbCreateInstance(ICakeContext, string, LocalDbVersion) Creates a server instance and starts the server.
Addin from Cake.SqlServer.dll
LocalDbDeleteInstance(ICakeContext, string) Deletes the LocalDB instance
Addin from Cake.SqlServer.dll
LocalDbStartInstance(ICakeContext, string) Starts the LocalDB instance. Instance must exist before you can start it.
Addin from Cake.SqlServer.dll
LocalDbStopInstance(ICakeContext, string) Stops the LocalDB instance.
Addin from Cake.SqlServer.dll
OpenSqlConnection(ICakeContext, string) Opens a new System.Data.SqlClient.SqlConnection with the given connection string.
Addin from Cake.SqlServer.dll
PublishDacpacFile(ICakeContext, string, string, FilePath, PublishDacpacSettings) Publish a dacpac file to a database.
Addin from Cake.SqlServer.dll
RestoreBacpac(ICakeContext, string, string, FilePath) Restores a bacpac file into a database.

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


Addin from Cake.SqlServer.dll
RestoreSqlBackup(ICakeContext, string, FilePath) Restores a database from a backup file.
Addin from Cake.SqlServer.dll
RestoreSqlBackup(ICakeContext, string, FilePath, RestoreSqlBackupSettings) Restores a database from a backup file.
Addin from Cake.SqlServer.dll
SetSqlCommandTimeout(ICakeContext, int) Sets the CommandTimeout property for all SqlCommands used internally
Addin from Cake.SqlServer.dll