public ActionResult CreateDatabase() {
            var dc = new DataClassesDataContext(ConnectionString);
            if (dc.DatabaseExists()) {
                dc.DeleteDatabase();
            }
            try {
                dc.CreateDatabase();

                // Add the necessary row for the sample client.
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "samplewebapiconsumer",
                    ClientSecret = "samplesecret",
                    Name = "Some sample client",
                });
                dc.Clients.InsertOnSubmit(new Client {
                    ClientIdentifier = "sampleImplicitConsumer",
                    Name = "Some sample client used for implicit grants (no secret)",
                    Callback = "http://localhost:59722/",
                });

                dc.SubmitChanges();

                // Force the user to log out because a new database warrants a new row in the users table, which we create
                // when the user logs in.
                FormsAuthentication.SignOut();
                ViewData["Success"] = true;
            }
            catch (SqlException ex) {
                ViewData["Error"] = string.Join("<br>", ex.Errors.OfType<SqlError>().Select(er => er.Message).ToArray());
            }

            return this.View("Database");
        }
 protected void Application_Error(object sender, EventArgs e) {
     // In the event of an unhandled exception, reverse any changes that were made to the database to avoid any partial database updates.
     var dataContext = DataContextSimple;
     if (dataContext != null) {
         dataContext.Transaction.Rollback();
         dataContext.Connection.Close();
         dataContext.Dispose();
         DataContextSimple = null;
     }
 }
 public ActionResult Index() {
     var dc = new DataClassesDataContext(ConnectionString);
     ViewBag.DBExists = dc.DatabaseExists();
     return View();
 }