SqlServerAliases.

CreateDatabase(ICakeContext, string, string, CreateDatabaseSettings) Method

Summary

Creates an empty database. If database with this name already exists, throws a SqlException. Allows to specify primary and log files location.
Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Containing Type
SqlServerAliases

Syntax

public static void CreateDatabase(this ICakeContext context, string connectionString, string databaseName, CreateDatabaseSettings settings)

Examples

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

    Task("Create-Database")
         .Does(() =>
         {
            var connectionString = @"Server=(localdb)\MSSqlLocalDb";
            var dbName = "CakeTest";
            var createSettings = new CreateDatabaseSettings()
                                         .WithPrimaryFile(@"C:\MyPath\DB\CakeTest.mdf")
                                         .WithLogFile(@"C:\MyPath\DB\CakeTest.ldf");
            CreateDatabase(connectionString, dbName, createSettings);
        });

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
settings CreateDatabaseSettings Settings object with parameters

Return Value

Type Description
void