久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

ASP.NET備份/恢復(fù)數(shù)據(jù)庫(kù)(轉(zhuǎn))

 風(fēng)云簫 2014-06-15
 /**********************************************************************************

 *
 * 功能說明:備份和恢復(fù)SQL Server數(shù)據(jù)庫(kù)
 * 作者: 劉功勛;
 * 版本:V0.1(C#2.0);時(shí)間:2007-1-1
 * 當(dāng)使用SQL Server時(shí),請(qǐng)引用 COM組件中的,SQLDMO.dll組件
 * 當(dāng)使用Access中,請(qǐng)瀏覽添加引用以下兩個(gè)dll
 *          引用C:\Program Files\Common Files\System\ado\msadox.dll,該DLL包含ADOX命名空間
 *          引用C:\Program Files\Common Files\System\ado\msjro.dll,該DLL包含JRO命名空間
 * *******************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using ADOX;//該命名空間包含創(chuàng)建ACCESS的類(方法)--解決方案 ==> 引用 ==> 添加引用 ==> 游覽找到.dll
using JRO;//該命名空間包含壓縮ACCESS的類(方法)

namespace EC
{
    /// <summary>
    /// 數(shù)據(jù)庫(kù)恢復(fù)和備份
    /// </summary>
    public class SqlBackObject
    {
        public SqlBackObject()
        {
            //
            // TODO: 在此處添加構(gòu)造函數(shù)邏輯
            //
        }

        #region SQL數(shù)據(jù)庫(kù)備份
       /// <summary>
        /// SQL數(shù)據(jù)庫(kù)備份
       /// </summary>
       /// <param name="ServerIP">SQL服務(wù)器IP或(Localhost)</param>
       /// <param name="LoginName">數(shù)據(jù)庫(kù)登錄名</param>
       /// <param name="LoginPass">數(shù)據(jù)庫(kù)登錄密碼</param>
       /// <param name="DBName">數(shù)據(jù)庫(kù)名</param>
       /// <param name="BackPath">備份到的路徑</param>
        public static void SQLBACK(string ServerIP,string LoginName,string LoginPass,string DBName,string BackPath)
        {
            SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
            SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
            try
            {
                oSQLServer.LoginSecure = false;
                oSQLServer.Connect(ServerIP, LoginName, LoginPass);
                oBackup.Database = DBName;
                oBackup.Files = BackPath;
                oBackup.BackupSetName = DBName;
                oBackup.BackupSetDescription = "數(shù)據(jù)庫(kù)備份";
                oBackup.Initialize = true;
                oBackup.SQLBackup(oSQLServer);

            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
            finally
            {
                oSQLServer.DisConnect();
            }
        }
        #endregion

        #region SQL恢復(fù)數(shù)據(jù)庫(kù)
        /// <summary>
        /// SQL恢復(fù)數(shù)據(jù)庫(kù)
        /// </summary>
        /// <param name="ServerIP">SQL服務(wù)器IP或(Localhost)</param>
        /// <param name="LoginName">數(shù)據(jù)庫(kù)登錄名</param>
        /// <param name="LoginPass">數(shù)據(jù)庫(kù)登錄密碼</param>
        /// <param name="DBName">要還原的數(shù)據(jù)庫(kù)名</param>
        /// <param name="BackPath">數(shù)據(jù)庫(kù)備份的路徑</param>

        public static void SQLDbRestore(string ServerIP,string LoginName,string LoginPass,string DBName,string BackPath)
        {
          
            SQLDMO.Restore orestore = new SQLDMO.RestoreClass();
            SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
            try
            {
                oSQLServer.LoginSecure = false;
                oSQLServer.Connect(ServerIP, LoginName, LoginPass);
                orestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
                orestore.Database = DBName;
                orestore.Files = BackPath;
                orestore.FileNumber = 1;
                orestore.ReplaceDatabase = true;
                orestore.SQLRestore(oSQLServer);

            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
            finally
            {
                oSQLServer.DisConnect();
            }
        }


        #endregion

        #region 根據(jù)指定的文件名稱創(chuàng)建Access數(shù)據(jù)庫(kù)
        /// <summary>
        /// 根據(jù)指定的文件名稱創(chuàng)建數(shù)據(jù)
        /// </summary>
        /// <param name="DBPath">絕對(duì)路徑+文件名稱</param>
        public static void CreateAccess(string DBPath)
        {
            if (File.Exists(DBPath))//檢查數(shù)據(jù)庫(kù)是否已存在
            {
                throw new Exception("目標(biāo)數(shù)據(jù)庫(kù)已存在,無法創(chuàng)建");
            }          
            DBPath = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+DBPath;
            //創(chuàng)建一個(gè)CatalogClass對(duì)象實(shí)例
            ADOX.CatalogClass cat = new ADOX.CatalogClass();
            //使用CatalogClass對(duì)象的Create方法創(chuàng)建ACCESS數(shù)據(jù)庫(kù)
            cat.Create(DBPath);

        }
        #endregion

        #region 壓縮Access數(shù)據(jù)庫(kù)
        /// <summary>
        /// 壓縮Access數(shù)據(jù)庫(kù)
        /// </summary>
        /// <param name="DBPath">數(shù)據(jù)庫(kù)絕對(duì)路徑</param>
        public static void CompactAccess(string DBPath)
        {
            if (!File.Exists(DBPath))
            {
                throw new Exception("目標(biāo)數(shù)據(jù)庫(kù)不存在,無法壓縮");
            }
          
            //聲明臨時(shí)數(shù)據(jù)庫(kù)名稱
            string temp = DateTime.Now.Year.ToString();
            temp += DateTime.Now.Month.ToString();
            temp += DateTime.Now.Day.ToString();
            temp += DateTime.Now.Hour.ToString();
            temp += DateTime.Now.Minute.ToString();
            temp += DateTime.Now.Second.ToString() + ".bak";
            temp = DBPath.Substring(0, DBPath.LastIndexOf("\\") + 1) + temp;
            //定義臨時(shí)數(shù)據(jù)庫(kù)的連接字符串
            string temp2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+temp;
            //定義目標(biāo)數(shù)據(jù)庫(kù)的連接字符串
            string DBPath2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+DBPath;
            //創(chuàng)建一個(gè)JetEngineClass對(duì)象的實(shí)例
            JRO.JetEngineClass jt = new JRO.JetEngineClass();
            //使用JetEngineClass對(duì)象的CompactDatabase方法壓縮修復(fù)數(shù)據(jù)庫(kù)
            jt.CompactDatabase(DBPath2, temp2);
            //拷貝臨時(shí)數(shù)據(jù)庫(kù)到目標(biāo)數(shù)據(jù)庫(kù)(覆蓋)
            File.Copy(temp, DBPath, true);
            //最后刪除臨時(shí)數(shù)據(jù)庫(kù)
            File.Delete(temp);
        }
        #endregion

        #region 備份Access數(shù)據(jù)庫(kù)
        /// <summary>
        /// 備份Access數(shù)據(jù)庫(kù)
        /// </summary>
        /// <param name="srcPath">要備份的數(shù)據(jù)庫(kù)絕對(duì)路徑</param>
        /// <param name="aimPath">備份到的數(shù)據(jù)庫(kù)絕對(duì)路徑</param>
        /// <returns></returns>
        public static void Backup(string srcPath,string aimPath)
        {
           
            if (!File.Exists(srcPath))
            {
                throw new Exception("源數(shù)據(jù)庫(kù)不存在,無法備份");
            }
            try
            {
                File.Copy(srcPath,aimPath,true);
            }
            catch(IOException ixp)
            {
                throw new Exception(ixp.ToString());
            }
           
        }

        #endregion

        #region 還原Access數(shù)據(jù)庫(kù)
        /// <summary>
        /// 還原Access數(shù)據(jù)庫(kù)
        /// </summary>
        /// <param name="bakPath">備份的數(shù)據(jù)庫(kù)絕對(duì)路徑</param>
        /// <param name="dbPath">要還原的數(shù)據(jù)庫(kù)絕對(duì)路徑</param>
        public static void RecoverAccess(string bakPath,string dbPath)
        {          
            if (!File.Exists(bakPath))
            {
                throw new Exception("備份數(shù)據(jù)庫(kù)不存在,無法還原");
            }
            try
            {
                File.Copy(bakPath, dbPath, true);
            }
            catch (IOException ixp)
            {
                throw new Exception(ixp.ToString());
            }       
        }       
        #endregion
    }
}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多