Exemplo n.º 1
0
 protected void WriteDatabaseInfo()
 {
     Utility.SetAppConfig(DatabaseAlias.ToString(), "User", txtUser.Text);
     Utility.SetAppConfig(DatabaseAlias.ToString(), "Password", txtPassword.Text);
     Utility.SetAppConfig(DatabaseAlias.ToString(), "ServerName", txtServer.Text);
     Utility.SetAppConfig(DatabaseAlias.ToString(), "WinAut", chkAutent.Checked.ToString());
     Utility.SetAppConfig(DatabaseAlias.ToString(), "DataBaseName", txtDataBase.Text.ToString());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Se for sql ele entra aqui para criar o banco  e as tabelas quando preciso
        /// </summary>
        public void isLocaldbServer()
        {
            bool InTransaction = false;
            //OleDbDao access = new OleDbDao(new ConnectionString());

            SqlDao access = new SqlDao(new ConnectionString());

            try
            {
                if (chkAutent.Checked == true)
                {
                    ConnectionStringServer = "Data Source=" + txtServer.Text + ";Integrated Security=True";
                }
                else
                {
                    ConnectionStringServer = "Data Source=" + txtServer.Text + ";User Id=" + txtUser.Text + ";Password="******"Dados de servidor invalidos. " + e.Message);
                }

                string vgStr = access.ExecuteScript(Server.MapPath("../Databases/" + DatabaseAlias + ".sql"), txtDataBase.Text, Server.MapPath("../App_Data/"));

                Utility.SetAppConfig(DatabaseAlias.ToString(), "StringConnection", ConnectionStringServer + String.Format(";AttachDbFilename=|DataDirectory|\\{0}.mdf;DataBase={0};", DatabaseName));

                Utility.SetAppConfig(DatabaseAlias.ToString(), "Type", cboDataType.Text);
                if (!access.DatabaseAlreadyExisted)
                {
                    Utility.SetAppConfig(DatabaseAlias.ToString(), "RunAdapter", "false");
                }
                WriteDatabaseInfo();
                if (InTransaction)
                {
                    access.CommitTrans();
                }
            }
            catch (Exception ex)
            {
                if (InTransaction)
                {
                    access.RollBack();
                }
                erros.Add("Erro ao iniciar a aplicação", ex.Message);
                ShowErrors();
            }
            finally
            {
                Utility.SetAppConfig(DatabaseAlias.ToString(), "CheckDatabase", "false");
                access.CloseConnection();
            }
        }
Exemplo n.º 3
0
        protected bool RunSilentAdapter()
        {
            string Error      = "";
            string ScriptFile = Server.MapPath(@"..\..\Databases\" + FileName + ".sql");

            if (!cbxTempDB.Checked)
            {
                ConnectionStringDBTemp = ConnectionStringDB;
            }

            if (System.IO.File.Exists(ScriptFile))
            {
                ConnectionStringDBTemp.DbName = NewDatabase;
                ReadyAdaptation ReadyAdap = new ReadyAdaptation(ConnectionStringDB, ConnectionStringDBTemp);
                List <string>   SQLScript = ReadyAdap.LoadScriptSQL(ScriptFile);

                ReadyAdap.Init();
                ReadyAdap.DBCreateByScript(GAdapter.Util.GetConnectionString(ConnectionStringDBTemp), SQLScript);

                if (!ReadyAdap.ExecErro && !ReadyAdap.Run(ref Error))                 // Cria o Script e roda a adaptação
                {
                    if (SilentMode)
                    {
                        ReadyAdap.CleanDatabase(GAdapter.Util.GetConnectionString(ConnectionStringDBTemp, true));
                        Utility.SetAppConfig(Session["DataBase"].ToString(), "RunAdapter", "false");
                        Response.Redirect(@"Default.aspx?SilentMode=true");
                    }
                    else
                    {
                        txtInformation.Text      = "Não existe diferenças entre os bancos.";
                        txtInformation.ForeColor = System.Drawing.Color.Blue;
                        ReadyAdap.CleanDatabase(GAdapter.Util.GetConnectionString(ConnectionStringDBTemp, true));
                    }
                }
                else
                {
                    txtInformation.Text      = Error + ReadyAdap.GetErro();
                    txtInformation.ForeColor = System.Drawing.Color.Red;
                }
                return(ReadyAdap.ExecErro);
            }
            else
            {
                txtInformation.Text      = "Script do banco de dados não foi encontrado em \r\n" + ScriptFile;
                txtInformation.ForeColor = System.Drawing.Color.Red;
            }
            return(true);
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (ConnectionInfoDB.ServerType != Util.DatabaseType.SQL)
                {
                    btnBackup.Visible = false;
                }

                string Arguments = Request.Params.Get("__EVENTARGUMENT");
                if (!IsPostBack)
                {
                    Session.Remove("Diffs");
                    Session.Remove("script");
                    Session.Remove("Warning");

                    this.txtDiffs.ForeColor = System.Drawing.Color.Blue;
                    this.LblDiffs.Text      = "Status";
                    this.LbDataBase.Text    = HttpContext.Current.Session["DatabaseName"].ToString();

                    if (!FinishAdp)
                    {
                        HttpContext.Current.Session["FinishAdp"] = true;
                    }
                    else if (!HasErro)
                    {
                        if (SilentMode)
                        {
                            Utility.SetAppConfig(Session["DataBase"].ToString(), "RunAdapter", "false");
                            Response.Redirect("Default.aspx?SilentMode=true");
                        }
                        else
                        {
                            this.txtDiffs.Text = "Execução do Script.... Sucesso \r\nVerificação do banco.... Sucesso \r\nNão existe diferença entre o banco e o script.";
                            Session.Abandon();
                            Response.Redirect(@"..\..\Pages\StartPage.aspx");
                        }
                        if (!Finish)
                        {
                            HiddenCanDeleteTemp.Value = "true";
                        }
                    }
                    else
                    {
                        this.txtDiffs.ForeColor = System.Drawing.Color.Red;
                        this.LblDiffs.Text      = "Erro ao Executar o Script";
                    }
                }

                if (Arguments == "ClickAdap")
                {
                    CheckAdapter();
                }

                if (Arguments == "DropDb")
                {
                    ReadyAdaptation ReadyAdap = new ReadyAdaptation();
                    ReadyAdap.DropDbTmp();
                    this.btn_exec.Enabled = false;
                    Finish = true;
                    HiddenCanDeleteTemp.Value = "false";
                }
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Se for sql ele entra aqui para criar o banco  e as tabelas quando preciso
        /// </summary>
        public void isSqlServer()
        {
            bool     InTransaction = false;
            OleDbDao access        = new OleDbDao(new ConnectionString());

            try
            {
                string vgProv = "";
                if (cboDataType.Text.ToUpper() != "OLEDB")
                {
                    vgProv = "SQLOLEDB.1";
                }
                else
                {
                    vgProv = txtProvider.Text;
                }
                if (chkAutent.Checked == true)
                {
                    ConnectionStringServer = "Provider=" + vgProv + ";Server=" + txtServer.Text + ";DataBase=;Integrated Security=SSPI";
                }
                else
                {
                    ConnectionStringServer = "Provider=" + vgProv + ";Server=" + txtServer.Text + ";DataBase=;User ID=" + txtUser.Text + ";Password= "******"Dados de servidor invalidos. " + e.Message);
                }

                if (access.Transaction == null)
                {
                    access.BeginTrans();
                    InTransaction = true;
                }
                string vgStr = access.ExecuteScript(Server.MapPath("../Databases/" + DatabaseAlias + ".sql"), txtDataBase.Text);
                if (cboDataType.Text.ToUpper() != "OLEDB")
                {
                    if (chkAutent.Checked == true)
                    {
                        Utility.SetAppConfig(DatabaseAlias.ToString(), "StringConnection", vgStr.Substring(vgStr.IndexOf(";") + 1).Replace("Persist Security Info=False;Initial Catalog", "Database"));
                    }
                    else
                    {
                        Utility.SetAppConfig(DatabaseAlias.ToString(), "StringConnection", vgStr.Substring(vgStr.IndexOf(";") + 1).Replace("Persist Security Info=False;Initial Catalog", "Database") + "Password="******";Trusted_Connection=false");
                    }
                }
                else
                {
                    Utility.SetAppConfig(DatabaseAlias.ToString(), "StringConnection", vgStr + "Password="******";");
                }

                Utility.SetAppConfig(DatabaseAlias.ToString(), "Type", cboDataType.Text);
                if (!access.DatabaseAlreadyExisted)
                {
                    Utility.SetAppConfig(DatabaseAlias.ToString(), "RunAdapter", "false");
                }
                WriteDatabaseInfo();
                if (InTransaction)
                {
                    access.CommitTrans();
                }
            }
            catch (Exception ex)
            {
                if (InTransaction)
                {
                    access.RollBack();
                }
                erros.Add("Erro ao iniciar a aplicação", ex.Message);
                ShowErrors();
            }
            finally
            {
                Utility.SetAppConfig(DatabaseAlias.ToString(), "CheckDatabase", "false");
                access.CloseConnection();
            }
        }