{"action":"opened","issue":{"url":"https://api.github.com/repos/DbUp/DbUp/issues/155","labels_url":"https://api.github.com/repos/DbUp/DbUp/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/DbUp/DbUp/issues/155/comments","events_url":"https://api.github.com/repos/DbUp/DbUp/issues/155/events","html_url":"https://github.com/DbUp/DbUp/issues/155","id":122939983,"number":155,"title":"Actively manage connections","user":{"login":"trickbooter","id":1949062,"avatar_url":"https://avatars.githubusercontent.com/u/1949062?v=3","gravatar_id":"","url":"https://api.github.com/users/trickbooter","html_url":"https://github.com/trickbooter","followers_url":"https://api.github.com/users/trickbooter/followers","following_url":"https://api.github.com/users/trickbooter/following{/other_user}","gists_url":"https://api.github.com/users/trickbooter/gists{/gist_id}","starred_url":"https://api.github.com/users/trickbooter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trickbooter/subscriptions","organizations_url":"https://api.github.com/users/trickbooter/orgs","repos_url":"https://api.github.com/users/trickbooter/repos","events_url":"https://api.github.com/users/trickbooter/events{/privacy}","received_events_url":"https://api.github.com/users/trickbooter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-18T12:23:22Z","updated_at":"2015-12-18T12:23:22Z","closed_at":null,"body":"Both TemporarySqlDatabase and UpgradeEngine do not offer direct control of the underlying SqlConnection object.\r\n\r\nWhen needing to perform a multi-pass deploy with the TemporarySqlDatabase object, open connections prevent correct disposal of the TemporarySqlDatabase.\r\n\r\n```\r\nvar uea = builder.build(); // first pass\r\nvar ueb = builder.build(); // same db, 2nd pass\r\nusing(var db = new TemporarySqlDatabase(cs))\r\n{\r\n  db.create();\r\n  uea.PerformUpgrade();\r\n  ueb.PerformUpgrade();\r\n} // dispose fails as we have an open connection on ueb that we cannot close.\r\n```\r\n\r\nMy specific scenario, I have a multi-db deploy with a circular reference (don't ask), so I have...\r\n\r\n```\r\nvar uea = buildera.Build(); // on ConnStr a (csa)\r\nvar ueb = builderb.Build(); // on ConnStr b (csb)\r\nusing(var dba = new TemporarySqlDatabase(csa))\r\n{\r\n  dba.Create();\r\n  using(var dbb = new TemporarySqlDatabase(csb))\r\n  {\r\n    dbb.Create();\r\n    uae.PerformUpgrade();\r\n    uab.PerformUpgrade();\r\n  } // dispose fails\r\n} // dispose fails\r\n```\r\n\r\nEither reveal the connection directly (like the SqlLite TemporarySqlLiteDatabase implementation) or more aggressively manage connections. Actively closing connections immediately after upgrade would be preferable. Likewise opening and closing connections on the TemporarySqlDatabase only when needed.\r\n\r\n"}}