Skip to content

Commit

Permalink
Improve error handling on SqlPackage.
Browse files Browse the repository at this point in the history
* If custom path to SQL Package is used, show that one if it is invalid.
* If error occurs during SQL Package deployment, do not output error to stderr.
  • Loading branch information
isaacabraham committed Feb 28, 2017
1 parent 33e702f commit 03245ab
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/app/FakeLib/Sql.DacPac.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ open Fake.EnvironmentHelper
open Fake.ProcessHelper
open System.IO
open Fake.FileSystem
open System.Diagnostics
open System

/// The type of action to execute.
type DeployAction =
Expand Down Expand Up @@ -95,15 +97,22 @@ let deployDb setParams =
failwith "No SqlPackage.exe filename was given."

if not (File.Exists args.SqlPackageToolPath) then
failwithf "Unable to find a valid instance of SqlPackage.exe. Paths checked were: %A." validPaths

shellExec {
Program = args.SqlPackageToolPath
CommandLine = sprintf """/Action:%s /SourceFile:"%s" /TargetConnectionString:"%s" %s /p:BlockOnPossibleDataLoss=%b /p:DropObjectsNotInSource=%b /p:CommandTimeout=%d /p:CreateNewDatabase=%b %s %s""" action args.Source args.Destination outputPath args.BlockOnPossibleDataLoss args.DropObjectsNotInSource args.Timeout args.RecreateDb additionalParameters variables
WorkingDirectory = ""
Args = [] }

|> function
let paths =
if validPaths |> List.contains args.SqlPackageToolPath then validPaths
else [ args.SqlPackageToolPath ]
failwithf "Unable to find a valid instance of SqlPackage.exe. Paths checked were: %A." paths

let result =
ExecProcessWithLambdas
(fun psi ->
psi.Arguments <- sprintf """/Action:%s /SourceFile:"%s" /TargetConnectionString:"%s" %s /p:BlockOnPossibleDataLoss=%b /p:DropObjectsNotInSource=%b /p:CommandTimeout=%d /p:CreateNewDatabase=%b %s %s""" action args.Source args.Destination outputPath args.BlockOnPossibleDataLoss args.DropObjectsNotInSource args.Timeout args.RecreateDb additionalParameters variables
psi.FileName <- args.SqlPackageToolPath)
TimeSpan.MaxValue
true
(printfn "SqlPackage error: %s")
(printfn "%s")

match result with
| 0 -> ()
| _ -> failwith "Error executing DACPAC deployment. Please see output for error details."

0 comments on commit 03245ab

Please sign in to comment.