protected void btnMssqlSetup_Click(object sender, EventArgs e) { if ((string)Session["Type"] == "ToWeb") { try { string ConnectionString = "Data Source={0};Initial Catalog={1};User ID={2};Password={3};Integrated Security={4};"; ConnectionString = string.Format(ConnectionString, txtWebServer.Text, txtWebCatalog.Text, txtWebUser.Text, txtWebPass.Text, cbTrusted.Checked); SqlConnection SConn = new SqlConnection(ConnectionString); SConn.Open(); SConn.Close(); if (Install(ConnectionString, "")) { string strLang = Session["lang"].ToString(); BSHelper.SaveWebConfig(ConnectionString, "System.Data.SqlClient"); Session["SetupCompleated"] = "OK"; Session["Step"] = "Settings"; Response.Redirect("Default.aspx?Setup=OK&lang=" + strLang); } } catch (Exception ex) { divError.Visible = true; lblError.Text = ex.Message; } } else { string ConnectionString = "Data Source={0};User ID={1};Password={2};Integrated Security={3};"; ConnectionString = string.Format(ConnectionString, txtWebServer.Text, txtWebUser.Text, txtWebPass.Text, cbTrusted.Checked); SqlConnection SConn = new SqlConnection(ConnectionString); SqlCommand SComm = new SqlCommand("CREATE DATABASE [" + txtWebCatalog.Text + "]", SConn); try { SConn.Open(); SComm.ExecuteNonQuery(); if (Install(ConnectionString, string.Format("USE [{0}]\n", txtWebCatalog.Text))) { string strLang = (string)Session["lang"]; Response.Redirect("Completed.aspx?Setup=" + BSHelper.SaveWebConfig(ConnectionString + string.Format("Initial Catalog={0};", txtWebCatalog.Text), "System.Data.SqlClient") + "&lang=" + strLang); } } catch (Exception ex) { divError.Visible = true; lblError.Text = ex.Message; } finally { if (SConn.State == ConnectionState.Open) { SConn.Close(); } } } }
protected void btnInstall_Click(object sender, EventArgs e) { string ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\{0}.mdb;", txtDatabaseName.Text); OleDbConnection OConn = new OleDbConnection(ConnectionString); StreamReader Sr = new StreamReader(Server.MapPath("~/Setup/Scripts/Access.sql")); try { File.Copy(Server.MapPath("~/Setup/Scripts/Blogsa.mdb"), Server.MapPath(string.Format("~/App_Data/{0}.mdb", txtDatabaseName.Text))); //Update WebSite Url string strUrl = Request.Url.AbsoluteUri.Substring(0 , Request.Url.AbsoluteUri.IndexOf(Request.Url.AbsolutePath) + (Request.ApplicationPath.Equals("/") ? 0 : Request.ApplicationPath.Length)) + "/"; OConn.Open(); while (!Sr.EndOfStream) { //Create DB string Commands = Sr.ReadLine().ToString(); if (!Commands.StartsWith("/*")) { OleDbCommand OComm = new OleDbCommand(Commands, OConn); OComm.ExecuteNonQuery(); OComm.Dispose(); } } Sr.Close(); string strLang = (string)Session["lang"]; string strRedirectPage = String.Format("Completed.aspx?Setup={0}&lang={1}", BSHelper.SaveWebConfig(ConnectionString, "System.Data.OleDb"), strLang); Response.Redirect(strRedirectPage, false); } catch (Exception ex) { BSLog l = new BSLog(); l.CreateDate = DateTime.Now; l.LogType = BSLogType.Error; l.LogID = Guid.NewGuid(); l.RawUrl = Request.RawUrl; l.Source = ex.Source; l.StackTrace = ex.StackTrace; l.TargetSite = ex.TargetSite; l.Url = Request.Url.ToString(); l.Save(); divError.Visible = true; lblError.Text = ex.Message; if (OConn.State == ConnectionState.Open) { OConn.Close(); } File.Delete(Server.MapPath("~/App_Data/" + txtDatabaseName.Text)); } finally { if (OConn.State == ConnectionState.Open) { OConn.Close(); } Sr.Close(); } }