예제 #1
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();
            }
        }