Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Services.Authentication Prototype/Persistence/DatabaseUtil.cs @ 3950

Last change on this file since 3950 was 3950, checked in by hmayr, 14 years ago

minor changes (#1046)

File size: 1.3 KB
Line 
1using System;
2
3namespace Persistence {
4  /// <summary>
5  /// combines multiple used static methods into one class
6  /// </summary>
7  public class DatabaseUtil {
8    /// <summary>
9    /// creates and returns a database connection, if possible
10    /// </summary>
11    /// <returns>database connection (could be null)</returns>
12    public static DataClassesDataContext createDataClassesDataContext() {
13      DataClassesDataContext db;
14      try {
15        db = new Persistence.DataClassesDataContext(@"C:\TEMP\HeuristicLabTest.mdf");
16      }
17      catch (Exception) {
18        return null;
19      }
20      return db;
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      if (db == null) {
29        throw new ArgumentNullException("db");
30      }
31     
32      if (db.DatabaseExists()) {
33        Console.WriteLine("Deleting old database...");
34        db.DeleteDatabase();
35        Console.WriteLine("Deleted old database!");
36      }
37
38      Console.WriteLine("Creating new database...");
39      db.CreateDatabase();
40      Console.WriteLine("Created new database!");
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.