Changeset 3972
- Timestamp:
- 06/28/10 19:21:50 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/Persistence/DatabaseUtil.cs
r3971 r3972 2 2 using System.Diagnostics; 3 3 using System.Data.Common; 4 using Persistence.Properties; 4 5 5 6 namespace Persistence { … … 9 10 public class DatabaseUtil { 10 11 11 p rotected static bool productionDatabase = true;12 public static bool ProductionDatabase { get; set; } 12 13 13 public static bool ProductionDatabase {14 get {15 return DatabaseUtil.productionDatabase;16 }17 set {18 DatabaseUtil.productionDatabase = value;19 }20 }21 22 14 /// <summary> 23 15 /// creates and returns a database connection, if possible … … 25 17 /// <returns>database connection (could be null)</returns> 26 18 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); 32 21 } 33 22 … … 37 26 /// <param name="db">DataClassesDataContext</param> 38 27 public static void createDatabase(DataClassesDataContext db) { 39 28 // delete old database 40 29 if (db.DatabaseExists()) { 41 Console.WriteLine("Deleting old database...");42 30 db.DeleteDatabase(); 43 Console.WriteLine("Deleted old database!");44 31 } 45 32 46 Console.WriteLine("Creating new database...");33 // create new database 47 34 db.CreateDatabase(); 48 35 49 36 DbCommand command = db.Connection.CreateCommand(); 50 37 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]"; 51 38 command.ExecuteNonQuery(); 52 53 39 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]"; 54 40 command.ExecuteNonQuery(); 55 41 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]"; 56 42 command.ExecuteNonQuery(); 57 Console.WriteLine("Created new database!");58 43 } 59 44 }
Note: See TracChangeset
for help on using the changeset viewer.