Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Services.Authentication Prototyp/HeuristicLab.Services.Authentication Prototype/Persistence/DatabaseUtil.cs @ 4427

Last change on this file since 4427 was 4427, checked in by mholper, 14 years ago
File size: 2.2 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Data.Common;
4using Persistence.Properties;
5
6namespace Persistence {
7  /// <summary>
8  /// combines multiple used static methods into one class
9  /// </summary>
10  public class DatabaseUtil {
11
12    public static bool ProductionDatabase { get; set; }
13
14    /// <summary>
15    /// creates and returns a database connection, if possible
16    /// </summary>
17    /// <returns>database connection (could be null)</returns>
18    public static DataClassesDataContext createDataClassesDataContext() {
19      return new DataClassesDataContext(
20        ProductionDatabase ? new Settings().DatabaseConnectionString : new Settings().DatabaseConnectionStringTesting);
21    }
22
23    /// <summary>
24    /// creates a new database out of the LINQ to SQL classes
25    /// </summary>
26    /// <param name="db">DataClassesDataContext</param>
27    public static void createDatabase(DataClassesDataContext db) {
28      // delete old database
29      if (db.DatabaseExists()) {
30        db.DeleteDatabase();
31      }
32
33      // create new database
34      db.CreateDatabase();
35
36      DbCommand command = db.Connection.CreateCommand();
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]";
38      command.ExecuteNonQuery();
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]";
40      command.ExecuteNonQuery();
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]";
42      command.ExecuteNonQuery();
43    }
44  }
45}
Note: See TracBrowser for help on using the repository browser.