Changeset 3972


Ignore:
Timestamp:
06/28/10 19:21:50 (9 years ago)
Author:
hmayr
Message:

minor changes (#1046)

File:
1 edited

Legend:

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

    r3971 r3972  
    22using System.Diagnostics;
    33using System.Data.Common;
     4using Persistence.Properties;
    45
    56namespace Persistence {
     
    910  public class DatabaseUtil {
    1011
    11     protected static bool productionDatabase = true;
     12    public static bool ProductionDatabase { get; set; }
    1213
    13     public static bool ProductionDatabase {
    14       get {
    15         return DatabaseUtil.productionDatabase;
    16       }
    17       set {
    18         DatabaseUtil.productionDatabase = value;
    19       }
    20     }
    21    
    2214    /// <summary>
    2315    /// creates and returns a database connection, if possible
     
    2517    /// <returns>database connection (could be null)</returns>
    2618    public static DataClassesDataContext createDataClassesDataContext() {
    27       if (productionDatabase) {
    28         return new Persistence.DataClassesDataContext(new Persistence.Properties.Settings().DatabaseConnectionString);
    29       } else {
    30         return new Persistence.DataClassesDataContext(new Persistence.Properties.Settings().DatabaseConnectionStringTesting);
    31       }
     19      return new DataClassesDataContext(
     20        ProductionDatabase ? new Settings().DatabaseConnectionString : new Settings().DatabaseConnectionStringTesting);
    3221    }
    3322
     
    3726    /// <param name="db">DataClassesDataContext</param>
    3827    public static void createDatabase(DataClassesDataContext db) {
    39        
     28      // delete old database
    4029      if (db.DatabaseExists()) {
    41         Console.WriteLine("Deleting old database...");
    4230        db.DeleteDatabase();
    43         Console.WriteLine("Deleted old database!");
    4431      }
    4532
    46       Console.WriteLine("Creating new database...");
     33      // create new database
    4734      db.CreateDatabase();
    48      
     35
    4936      DbCommand command = db.Connection.CreateCommand();
    5037      command.CommandText = "CREATE UNIQUE NONCLUSTERED INDEX [IDXRoleName] ON [dbo].[HeuristicLabRole](  [roleName] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]";
    5138      command.ExecuteNonQuery();
    52 
    5339      command.CommandText = "CREATE UNIQUE NONCLUSTERED INDEX [IDXUserName] ON [dbo].[HeuristicLabUser](  [UserName] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]";
    5440      command.ExecuteNonQuery();
    5541      command.CommandText = "CREATE UNIQUE NONCLUSTERED INDEX [IDXUserEmail] ON [dbo].[HeuristicLabUser](   [Email] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]";
    5642      command.ExecuteNonQuery();
    57       Console.WriteLine("Created new database!");
    5843    }
    5944  }
Note: See TracChangeset for help on using the changeset viewer.