SqlServerAliases.

CreateDatabaseIfNotExists(ICakeContext, string, string) Method

Summary

Creates an empty database if another database with the same does not already exist.
Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Containing Type
SqlServerAliases

Syntax

public static void CreateDatabaseIfNotExists(this ICakeContext context, string connectionString, string databaseName)

Examples

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

    Task("Create-Database-If-Not-Exists")
         .Does(() =>
         {
            var connectionString = @"Server=(localdb)\MSSqlLocalDb";
            var dbName = "CakeTest";
            CreateDatabaseIfNotExists(connectionString, dbName);
        });

Attributes

Type Description
CakeMethodAliasAttribute

Parameters

Name Type Description
context ICakeContext The Cake context
connectionString string The connection string. For this operation, it is recommended to connect to the master database (default). If there are changing parameters, Microsoft.Data.SqlClient.SqlConnectionStringBuilder is recommended to escape input.
databaseName string Database name to be created

Return Value

Type Description
void