SqlServerAliases Class

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"

Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Base Types
  • Object
graph BT Type-->Base0["Object"] Type["SqlServerAliases"] class Type type-node

Syntax

public static class SqlServerAliases

Attributes

Type Description
CakeAliasCategoryAttribute

Methods

Name Value Summary
CreateDatabase(ICakeContext, string, string, CreateDatabaseSettings) void
Creates an empty database. If database with this name already exists, throws a SqlException. Allows to specify primary and log files location.
static
CreateDatabase(ICakeContext, string, string) void
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.
static
CreateDatabaseIfNotExists(ICakeContext, string, string, CreateDatabaseSettings) void
Creates an empty database if another database with the same does not already exist.
static
CreateDatabaseIfNotExists(ICakeContext, string, string) void
Creates an empty database if another database with the same does not already exist.
static
DatabaseExists(ICakeContext, string, string) bool
Test if the database exists
static
DropAndCreateDatabase(ICakeContext, string, string, CreateDatabaseSettings) void
First drops, then recreates the database
static
DropAndCreateDatabase(ICakeContext, string, string) void
First drops, then recreates the database
static
DropDatabase(ICakeContext, string, string) void
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.
static
ExecuteSqlCommand(ICakeContext, SqlConnection, string) void
Execute any SQL command.
static
ExecuteSqlCommand(ICakeContext, string, string) void
Execute any SQL command.
static
ExecuteSqlFile(ICakeContext, SqlConnection, FilePath) void
Reads SQL commands from a file and executes them.
static
ExecuteSqlFile(ICakeContext, string, FilePath) void
Reads SQL commands from a file and executes them.
static
OpenSqlConnection(ICakeContext, string) SqlConnection
Opens a new Microsoft.Data.SqlClient.SqlConnection with the given connection string.
static
SetSqlCommandTimeout(ICakeContext, int) void
Sets the CommandTimeout property for all SqlCommands used internally
static

Extension Methods

Name Value Summary
ToDictionary() IDictionary<string, object>
Requires the Cake.DeployParams addin