When executing two delete statements in the wrong order,
e.g. violating the foreing key constraint, so for example, deleting headers table before rows table,
the type provider does not bubble up the sql exception at runtime,
but gives instead a type initialization exception which does not allow to properly track the issue,
without executing the command separately.
Repro steps
Please provide the steps required to reproduce the problem
(* connectionString is one of SqlServer 2014,
whereas devConnectionString is of SqlServer 2008 *)
[<Literal>]
let deleteMovement =
@"DELETE
FROM Movements
WHERE ID= @id
"
type DeleteMovement = SqlCommandProvider<deleteMovement, connectionString>
let delMovement id =
use cmd = new DeleteMovement(devConnectionString)
in printfn "%s" (cmd.ToTraceString id) ;
cmd.Execute(id)
[<Literal>]
let deleteMovementRows =
@"DELETE
FROM MovementRows
WHERE movement_ID = @MovementId
"
type DeleteMovementRows = SqlCommandProvider<deleteMovementRows, connectionString>
let delMovementRows movementId =
use cmd = new DeleteMovementRows(devConnectionString)
in printfn "%s" (cmd.ToTraceString movementId) ;
cmd.Execute(movementId)
let deleteMovementsAndRows ids =
ids |> Seq.iter(fun x ->
delMovement x |> printfn "deleted movements %A";
delMovementRows x |> printfn "deletes movements rows %A"
)
Expected behavior
SqlCommandProvider should raise an exception at runtime,
containing the appropriate error with constraint violation on foreign key,
or whatever constraint violation happens.
Actual behavior
An unhandled exception of type System.TypeInitializationException occurred in [...].exe
Additional information: The type initializer for <StartupCode$MessageGenerator>.$Program threw an exception.
Known workarounds
No workarounds at this time.
just grab sql and execute it against database in the same order of execution, to get the correct error message that should be displayed
Related information
Windows 8 64 bit
latest stable release
Sql server 2008 for query execution, Sql server 2014 for type provider generation
Description
When executing two delete statements in the wrong order, e.g. violating the foreing key constraint, so for example, deleting headers table before rows table, the type provider does not bubble up the sql exception at runtime, but gives instead a type initialization exception which does not allow to properly track the issue, without executing the command separately.
Repro steps
Please provide the steps required to reproduce the problem
Expected behavior
SqlCommandProvider
should raise an exception at runtime, containing the appropriate error with constraint violation on foreign key, or whatever constraint violation happens.Actual behavior
An unhandled exception of type
System.TypeInitializationException
occurred in [...].exeAdditional information: The type initializer for
<StartupCode$MessageGenerator>.$Program
threw an exception.Known workarounds
No workarounds at this time. just grab sql and execute it against database in the same order of execution, to get the correct error message that should be displayed
Related information