SqlServerAliases.

OpenSqlConnection(ICakeContext, string) Method

Summary

Opens a new Microsoft.Data.SqlClient.SqlConnection with the given connection string.
Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Containing Type
SqlServerAliases

Syntax

public static SqlConnection OpenSqlConnection(this ICakeContext context, string connectionString)

Examples

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

     Task("Sql-Operations")
         .Does(() =>
         {
             using (var connection = OpenSqlConnection(@"Data Source=(localdb)\MSSqlLocalDb;Initial Catalog=MyDatabase"))
             {
                 ExecuteSqlCommand(connection, "...");
                 ExecuteSqlFile(connection, "./somePath/MyScript.sql");
             }
         });

Attributes

Type Description
CakeMethodAliasAttribute

Parameters

Name Type Description
context ICakeContext The Cake context.
connectionString string The connection string. You may want to specify Initial Catalog. If there are changing parameters, Microsoft.Data.SqlClient.SqlConnectionStringBuilder is recommended to escape input.

Return Value

Type Description
SqlConnection