SqlServerAliases.

DatabaseExists(ICakeContext, string, string) Method

Summary

Test if the database exists
Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Containing Type
SqlServerAliases

Syntax

public static bool DatabaseExists(this ICakeContext context, string connectionString, string databaseName)

Examples

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

    Task("Deploy-Database")
         .Does(() =>
         {
            var connectionString = @"Server=(localdb)\MSSqlLocalDb";
            var dbName = "CakeTest";

            if (DatabaseExists(connectionString, dbName))
            {
                throw new Exception("A database with the same name already exists");
            }
            // do other stuff
        });

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 test

Return Value

Type Description
bool