The last post contains the description of a
sqlMonad. It also happens to contain a silly and obvious (aren’t they all in hindsight) bug. The bug is in implementing the containing
CmdSqlBuilder with the
While the intent was good (the class wraps resources that should be promptly disposed of –
let connection = new SqlConnection(connectionString) let cmd = new SqlCommand(name, connection)
there is no real opportunity to use it in this way, since the underlying object is statically created in advance and so cannot be used as disposable objects normally are!
The fix is to clean thing up after each run like so:
member this.Run( m : CmdSqlMonad<'a>) = try m cmd finally dispose()
Here, after each run,
dispose() function should do its work closing connections and disposing of the command object. Disposable pattern should not be implemented as its application in this case makes no sense.