Improve Connection.Start and Connection.Finished calls #10

Closed
hisystems opened this Issue Mar 4, 2012 · 1 comment

Projects

None yet

1 participant

@hisystems
Owner

Currently, before accessing the database the connection must be ensured to be opened. This is achieved with the Database.Connection.Start. This call will open the connection if it has not already been opened. Similarly the Database.Connection.Finished call will close the connection if it is the last Finished call. If the Finished call is embedded within the bounds of a Start / Finished call set then the Finished call does nothing, it only decrements a counter.

The issue with this approach is that if an exception occurs the Finished call may not be called (unless it is in the finally section of a try / catch).

@hisystems
Owner

A new class should be created called ConnectionScope with a Database argument. The constructor will call the Connection.Start method and the Dispose method will call the Finished method. This will ensure that if an unexpected exception occurs the connection is correctly closed. This should also work when used in conjunction with a System.Transactions.TransactionScope object.

All of the code in the Database class should be updated to utilise this new construct.

@hisystems hisystems was assigned Mar 4, 2012
@hisystems hisystems added a commit that referenced this issue Mar 21, 2012
@hisystems Added ConnectionScope construct. #10.
Provides the ability to open and close a database connection and also ensure that unexpected will still close the connection. Typically this will be used with a Using construct.
d1aa315
@hisystems hisystems added a commit that closed this issue Mar 21, 2012
@hisystems Implemented new ConnectionScope construct throughout library. Closes #10
.

This involved refactoring some of the code to utilise the Using construct. In particular, utilising the Using construct for the IDataReader returned from an SQL execute statement.
c22a005
@hisystems hisystems closed this in c22a005 Mar 21, 2012
@hisystems hisystems added a commit that referenced this issue Mar 22, 2012
@hisystems Correctly accounts for situations where Dispose is called twice. Asso…
…ciated with closed call #10.
9ab528f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment