public ActionResult Step1(SQLInstallViewModel info) { ViewData["StepNumber"] = 1; if (info.UseIntegratedSecurity) { ModelState.Remove("DatabaseLogin"); ModelState.Remove("DatabasePassword"); } if (!ModelState.IsValid) return View(info); SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder(); connectionString.DataSource = info.DatabaseServer; connectionString.InitialCatalog = info.DatabaseName; connectionString.MultipleActiveResultSets = true; connectionString.IntegratedSecurity = info.UseIntegratedSecurity; ; if (!info.UseIntegratedSecurity) { connectionString.UserID = info.DatabaseLogin; connectionString.Password = info.DatabasePassword; } SqlConnection connection = new SqlConnection(connectionString.ToString()); try { connection.Open(); string sql = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/mesoBoardFresh.sql")); string[] cmds = sql.Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries); SqlCommand command = new SqlCommand(); command.Connection = connection; foreach (string cmd in cmds) { command.CommandText = cmd; command.ExecuteNonQuery(); } } catch (Exception ex) { TempData[ViewDataKeys.GlobalMessages.Notice] = "Unable to connect to SQL server, check connection information"; TempData[ViewDataKeys.GlobalMessages.Error] = ex.Message; return View(info); } finally { connection.Close(); connection.Dispose(); } Session[SessionSqlInfoKey] = info; return RedirectToAction("Step2"); }
public ActionResult Step1() { ViewData["StepNumber"] = 1; SQLInstallViewModel model = new SQLInstallViewModel { DatabaseServer = "localhost", UseIntegratedSecurity = false, }; return View(model); }