Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/10 18:28:12 (14 years ago)
Author:
bfarka
Message:

made Database configable with app.config in the Persistence Project --> 2 different DBs can be configured (one for UnitTesting and a real one) (#1063)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/Persistence/DatabaseUtil.cs

    r3955 r3970  
    11using System;
     2using System.Diagnostics;
    23
    34namespace Persistence {
     
    67  /// </summary>
    78  public class DatabaseUtil {
     9
     10    protected static bool productionDatabase = true;
     11
     12    public static bool ProductionDatabase {
     13      get {
     14        return DatabaseUtil.productionDatabase;
     15      }
     16      set {
     17        DatabaseUtil.productionDatabase = value;
     18      }
     19    }
     20   
    821    /// <summary>
    922    /// creates and returns a database connection, if possible
     
    1124    /// <returns>database connection (could be null)</returns>
    1225    public static DataClassesDataContext createDataClassesDataContext() {
    13         return  new Persistence.DataClassesDataContext(@"C:\TEMP\HeuristicLabTest.mdf");
     26      if (productionDatabase) {
     27        return new Persistence.DataClassesDataContext(new Persistence.Properties.Settings().DatabaseConnectionString);
     28      } else {
     29        return new Persistence.DataClassesDataContext(new Persistence.Properties.Settings().DatabaseConnectionStringTesting);
     30      }
    1431    }
    1532
     
    1936    /// <param name="db">DataClassesDataContext</param>
    2037    public static void createDatabase(DataClassesDataContext db) {
    21       if (db == null) {
    22         throw new ArgumentNullException("db");
    23       }
    24      
     38       
    2539      if (db.DatabaseExists()) {
    2640        Console.WriteLine("Deleting old database...");
Note: See TracChangeset for help on using the changeset viewer.