Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/Results.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/Results.cs	(revision 2220)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/Results.cs	(revision 2221)
@@ -73,5 +73,5 @@
     public Results(IModelingDatabase database) {
       this.database = database;
-      multiDimensionalOrdinalVariables = database.GetAllResultsForInputVariables().Select(x => "VariableImpacts: "+ x.Name).ToArray();
+      multiDimensionalOrdinalVariables = database.GetAllResultsForInputVariables().Select(x => "VariableImpacts: " + x.Name).ToArray();
     }
 
@@ -85,14 +85,14 @@
 
     private IEnumerable<ResultsEntry> SelectRows() {
-      database.GetAllModelResults();
+      database.Connect();      
       entries = new List<ResultsEntry>();
       foreach (var model in database.GetAllModels()) {
         ResultsEntry modelEntry = new ResultsEntry();
-        foreach(var modelResult in database.GetModelResults(model)) {
+        foreach (var modelResult in database.GetModelResults(model)) {
           modelEntry.Set(modelResult.Result.Name, modelResult.Value);
         }
         modelEntry.Set("PersistedData", database.GetModelData(model));
         modelEntry.Set("TargetVariable", model.TargetVariable.Name);
-        Dictionary<HeuristicLab.Modeling.Database.IVariable, ResultsEntry> inputVariableResultsEntries = 
+        Dictionary<HeuristicLab.Modeling.Database.IVariable, ResultsEntry> inputVariableResultsEntries =
           new Dictionary<HeuristicLab.Modeling.Database.IVariable, ResultsEntry>();
 
@@ -107,5 +107,5 @@
         entries.Add(modelEntry);
       }
-      
+      database.Disconnect();
       FireChanged();
       cached = true;
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/TableResultsView.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/TableResultsView.cs	(revision 2220)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/TableResultsView.cs	(revision 2221)
@@ -68,5 +68,5 @@
       if (e.Button == MouseButtons.Left && e.Clicks == 2) {
         DataGridView.HitTestInfo hitInfo = dataGridView.HitTest(e.X, e.Y);
-        ResultsEntry entry = (ResultsEntry)dataGridView.Rows[hitInfo.RowIndex].Tag;
+        ResultsEntry entry = (ResultsEntry)dataGridView.Rows[hitInfo.RowIndex].Tag;        
         var model = (IItem)PersistenceManager.RestoreFromGZip((byte[])entry.Get("PersistedData"));
         PluginManager.ControlManager.ShowControl(model.CreateView());
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2220)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2221)
@@ -17,15 +17,33 @@
     public DatabaseService(string connection) {
       this.connection = connection;
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        if (!ctx.DatabaseExists())
-          ctx.CreateDatabase();
-      }
+      Connect();
+      if (!ctx.DatabaseExists())
+        ctx.CreateDatabase();
     }
 
     private void EmptyDatabase() {
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        ctx.DeleteDatabase();
-        ctx.CreateDatabase();
-      }
+      ctx.DeleteDatabase();
+      ctx.CreateDatabase();
+    }
+
+    private ModelingDataContext ctx;
+    public void Connect() {
+      if (ctx != null)
+        return;
+
+      ctx = new ModelingDataContext(connection);
+      DataLoadOptions dlo = new DataLoadOptions();
+      dlo.LoadWith<ModelResult>(mr => mr.Result);
+      dlo.LoadWith<InputVariableResult>(ir => ir.Variable);
+      dlo.LoadWith<InputVariableResult>(ir => ir.Result);
+      dlo.LoadWith<Model>(m => m.TargetVariable);
+      ctx.LoadOptions = dlo;
+    }
+
+    public void Disconnect() {
+      if (ctx == null)
+        return;
+      ctx.Dispose();
+      ctx = null;
     }
 
@@ -103,23 +121,20 @@
 
     public Dataset GetDataset() {
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        if (ctx.Problems.Count() != 1)
-          throw new InvalidOperationException("Could not get dataset. No or more than one problems are persisted in the database.");
-
-        Problem problem = ctx.Problems.Single();
-        return problem.Dataset;
-      }
+      if (ctx.Problems.Count() != 1)
+        throw new InvalidOperationException("Could not get dataset. No or more than one problems are persisted in the database.");
+
+      Problem problem = ctx.Problems.Single();
+      return problem.Dataset;
+
     }
 
     public Problem GetOrCreateProblem(Dataset dataset) {
       Problem problem;
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        if (ctx.Problems.Count() == 0)
-          problem = PersistProblem(dataset);
-        else
-          problem = ctx.Problems.Single();
-        if (problem.Dataset.ToString() != dataset.ToString())
-          throw new InvalidOperationException("Could not persist dataset. The database already contains a different dataset.");
-      }
+      if (ctx.Problems.Count() == 0)
+        problem = PersistProblem(dataset);
+      else
+        problem = ctx.Problems.Single();
+      if (problem.Dataset.ToString() != dataset.ToString())
+        throw new InvalidOperationException("Could not persist dataset. The database already contains a different dataset.");
       return problem;
     }
@@ -165,7 +180,5 @@
     public Dictionary<string, Variable> GetAllVariables() {
       Dictionary<string, Variable> dict = new Dictionary<string, Variable>();
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        dict = ctx.Variables.ToDictionary<Variable, string>(delegate(Variable v) { return v.Name; });
-      }
+      dict = ctx.Variables.ToDictionary<Variable, string>(delegate(Variable v) { return v.Name; });
       return dict;
     }
@@ -192,13 +205,9 @@
 
     public IEnumerable<IResult> GetAllResults() {
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        return ctx.Results.ToList().Cast<IResult>();
-      }
+      return ctx.Results.ToList().Cast<IResult>();
     }
 
     public IEnumerable<IResult> GetAllResultsForInputVariables() {
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        return (from ir in ctx.InputVariableResults select ir.Result).Distinct().ToList().Cast<IResult>();
-      }
+      return (from ir in ctx.InputVariableResults select ir.Result).Distinct().ToList().Cast<IResult>();
     }
 
@@ -207,9 +216,4 @@
     #region ModelResult
     public IEnumerable<IModelResult> GetModelResults(IModel model) {
-      ModelingDataContext ctx = new ModelingDataContext(connection);
-      DataLoadOptions dlo = new DataLoadOptions();
-      dlo.LoadWith<ModelResult>(mr => mr.Result);
-      ctx.LoadOptions = dlo;
-
       var results = from result in ctx.ModelResults
                     where result.Model == model
@@ -217,27 +221,8 @@
       return results.ToList().Cast<IModelResult>();
     }
-
-    public void GetAllModelResults() {
-      ModelingDataContext ctx = new ModelingDataContext(connection);
-      DataLoadOptions dlo = new DataLoadOptions();
-      dlo.LoadWith<ModelResult>(mr => mr.Result);
-      dlo.LoadWith<ModelResult>(mr => mr.Model);
-      ctx.LoadOptions = dlo;
-
-      var results = from result in ctx.ModelResults
-                    select result;
-      results.ToList();     
-
-    }
     #endregion
 
     #region InputVariableResults
     public IEnumerable<IInputVariableResult> GetInputVariableResults(IModel model) {
-      ModelingDataContext ctx = new ModelingDataContext(connection);
-      DataLoadOptions dlo = new DataLoadOptions();
-      dlo.LoadWith<InputVariableResult>(ir => ir.Variable);
-      dlo.LoadWith<InputVariableResult>(ir => ir.Result);      
-      ctx.LoadOptions = dlo;
-
       var inputResults = from ir in ctx.InputVariableResults
                          where ir.Model == model
@@ -250,20 +235,14 @@
     #region Model
     public IEnumerable<IModel> GetAllModels() {
-      ModelingDataContext ctx = new ModelingDataContext(connection);
-      DataLoadOptions dlo = new DataLoadOptions();
-      dlo.LoadWith<Model>(m => m.TargetVariable);
-      ctx.LoadOptions = dlo;
       return ctx.Models.ToList().Cast<IModel>();
     }
 
     public byte[] GetModelData(IModel model) {
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        var data = (from md in ctx.ModelData
-                    where md.Model == model
-                    select md);
-        if (data.Count() == 0)
-          return null;
-        return data.Single().Data;
-      }
+      var data = (from md in ctx.ModelData
+                  where md.Model == model
+                  select md);
+      if (data.Count() == 0)
+        return null;
+      return data.Single().Data;
     }
     #endregion
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database/3.2/IModelingDatabase.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database/3.2/IModelingDatabase.cs	(revision 2220)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database/3.2/IModelingDatabase.cs	(revision 2221)
@@ -35,5 +35,6 @@
     IEnumerable<IInputVariableResult> GetInputVariableResults(IModel model);
 
-    void GetAllModelResults();
+    void Connect();
+    void Disconnect();
   }
 }
