Exemplo n.º 1
0
        static public bool Restaurar_BD(string pRuta, GConexion pConexion)
        {
            string sBackup = "RESTORE DATABASE " + pConexion.Base_Datos +
                             " FROM DISK = '" + pRuta + "'" +
                             " WITH REPLACE";

            SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();

            csb.DataSource = pConexion.Origen;
            // Es mejor abrir la conexión con la base Master
            csb.InitialCatalog     = "master";
            csb.IntegratedSecurity = true;
            //csb.ConnectTimeout = 480; // el predeterminado es 15

            using (SqlConnection con = new SqlConnection(csb.ConnectionString))
            {
                try
                {
                    con.Open();

                    SqlCommand cmdBackUp = new SqlCommand(sBackup, con);
                    cmdBackUp.ExecuteNonQuery();
                    con.Close();
                    return(true);
                }
                catch { return(false); }
            }
        }
Exemplo n.º 2
0
        static public bool Salvar_BD(string pRuta, GConexion pConexion)
        {
            string sBackup = "BACKUP DATABASE " + pConexion.Base_Datos + " TO DISK = N'" + pRuta +
                             "' WITH NOFORMAT, NOINIT, NAME =N'" + pConexion.Base_Datos + ",SKIP, STATS = 10 '";

            //" TO DISK = N'" + this.txtRuta.Text +
            // "' Full Database Backup ,SKIP, STATS = 10 '";
            SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();

            csb.DataSource     = pConexion.Origen;
            csb.InitialCatalog = pConexion.Base_Datos;
            csb.Password       = pConexion.Password;
            csb.UserID         = pConexion.Usuario;

            using (SqlConnection con = new SqlConnection(csb.ConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmdBackUp = new SqlCommand(sBackup, con);
                    cmdBackUp.ExecuteNonQuery();
                    con.Close();
                    return(true);
                }
                catch { return(false); }
            }
        }
Exemplo n.º 3
0
 public GTabla()
 {
     aTabla     = null;
     aAdaptador = null;
     aComando   = null;
     aSQL       = "";
     aConexion  = null;
 }
Exemplo n.º 4
0
 public GRegistro()
 {
     aTabla      = null;
     aRegistro   = null;
     aAdaptador  = null;
     aComando    = null;
     aSQL        = "";
     aConnection = null;
 }
Exemplo n.º 5
0
 public GConexion(GConexion gConexion)
 {
     aTProveedor = gConexion.Tipo_Proveedor;
     aOrigen     = gConexion.Origen;
     aBaseDatos  = gConexion.Base_Datos;
     aUsuario    = gConexion.Usuario;
     aPassword   = gConexion.Password;
     aAssigned   = gConexion.Asignada;
     this.AsignarStringConexion();
 }
Exemplo n.º 6
0
        public GTabla(string pSQL, GConexion pConexion)
        {
            aSQL      = pSQL;
            aTabla    = new DataTable();
            aConexion = pConexion;

            switch (aConexion.Tipo_Proveedor)
            {
            case TProveedor.Access:
            {
                aAdaptador              = new OleDbDataAdapter(aSQL, ((OleDbConnection)aConexion.GetConnection));
                aComando                = new OleDbCommandBuilder((OleDbDataAdapter)aAdaptador);
                aComando.QuotePrefix    = "[";
                aComando.QuoteSuffix    = "]";
                aComando.ConflictOption = ConflictOption.OverwriteChanges;
                ((OleDbDataAdapter)aAdaptador).UpdateCommand = ((OleDbCommandBuilder)aComando).GetUpdateCommand();
                ((OleDbDataAdapter)aAdaptador).InsertCommand = ((OleDbCommandBuilder)aComando).GetInsertCommand();
                ((OleDbDataAdapter)aAdaptador).DeleteCommand = ((OleDbCommandBuilder)aComando).GetDeleteCommand();
                break;
            }

            case TProveedor.SQL_Server:
            {
                aAdaptador              = new SqlDataAdapter(aSQL, (SqlConnection)aConexion.GetConnection);
                aComando                = new SqlCommandBuilder((SqlDataAdapter)aAdaptador);
                aComando.QuotePrefix    = "[";
                aComando.QuoteSuffix    = "]";
                aComando.ConflictOption = ConflictOption.OverwriteChanges;
                ((SqlDataAdapter)aAdaptador).UpdateCommand = ((SqlCommandBuilder)aComando).GetUpdateCommand();
                ((SqlDataAdapter)aAdaptador).InsertCommand = ((SqlCommandBuilder)aComando).GetInsertCommand();
                ((SqlDataAdapter)aAdaptador).DeleteCommand = ((SqlCommandBuilder)aComando).GetDeleteCommand();
                break;
            }

            case TProveedor.Oracle:
            {
                aAdaptador              = new OdbcDataAdapter(aSQL, (OdbcConnection)aConexion.GetConnection);
                aComando                = new OdbcCommandBuilder((OdbcDataAdapter)aAdaptador);
                aComando.QuotePrefix    = "[";
                aComando.QuoteSuffix    = "]";
                aComando.ConflictOption = ConflictOption.OverwriteChanges;
                ((OdbcDataAdapter)aAdaptador).UpdateCommand = ((OdbcCommandBuilder)aComando).GetUpdateCommand();
                ((OdbcDataAdapter)aAdaptador).InsertCommand = ((OdbcCommandBuilder)aComando).GetInsertCommand();
                ((OdbcDataAdapter)aAdaptador).DeleteCommand = ((OdbcCommandBuilder)aComando).GetDeleteCommand();
                break;
            }
            }
        }