Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling on SqlPackage. #1476

Merged
merged 1 commit into from
Mar 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."