Index: ActiviteitenOpvolging/ActiviteitenOpvolging/mappers/CacheMapper.vb =================================================================== diff -u -r1707 -r1710 --- ActiviteitenOpvolging/ActiviteitenOpvolging/mappers/CacheMapper.vb (.../CacheMapper.vb) (revision 1707) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/mappers/CacheMapper.vb (.../CacheMapper.vb) (revision 1710) @@ -165,9 +165,12 @@ 'Initialise the list with work items. Dim workItems As New List(Of IWorkItem) + + 'Declare datareader. + Dim dr As OdbcDataReader = Nothing Try 'Execute query and store datareader. - Dim dr = ExecuteIntoDataReader(query) + dr = ExecuteIntoDataReader(query) 'Fetch amount of activities. Dim activityAmount = FetchNumberOfActivities(workPostIndex) @@ -191,13 +194,15 @@ workItems.Add(workItem) End While - 'Close connection. - dr.Close() - 'Return the list. Return workItems Catch ex As Exception Throw New Exception($"An error occured while fetching the work items from Caché.{vbNewLine}{ex.Message}") + Finally + 'Close connection if datareader is not nothing. + If Not IsNothing(dr) Then + dr.Close() + End If End Try End Function