SqlServerAliases.

ExecuteSqlFile(ICakeContext, SqlConnection, FilePath) Method

Summary

Reads SQL commands from a file and executes them.
Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Containing Type
SqlServerAliases

Syntax

public static void ExecuteSqlFile(this ICakeContext context, SqlConnection connection, FilePath sqlFile)

Examples

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

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

Attributes

Type Description
CakeMethodAliasAttribute

Parameters

Name Type Description
context ICakeContext The Cake context.
connection SqlConnection The connection to use. The connection must be open. See Cake.SqlServer.SqlServerAliases.OpenSqlConnection(Cake.Core.ICakeContext,System.String).
sqlFile FilePath Path to a file with SQL commands.

Return Value

Type Description
void