Пример #1
0
        /// <summary>
        /// 还原数据库
        /// </summary>
        /// <returns>string</returns>
        private string doRestore()
        {
            string bakname = IRequest.GetFormString("BackUp_File");
            string bakpath = Request.MapPath("~\\App_Data") + "\\" + bakname;

            if (dbtype.ToLower() != "dcsqlite")
            {
                SQLDMO.Restore   oRestore   = new SQLDMO.RestoreClass();
                SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
                try
                {
                    oSQLServer.LoginSecure = false;
                    oSQLServer.Connect(conn, dbuser, dbpwd);
                    oRestore.Action          = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
                    oRestore.Database        = dbname;
                    oRestore.Files           = bakpath;
                    oRestore.FileNumber      = 1;
                    oRestore.ReplaceDatabase = true;
                    oRestore.SQLRestore(oSQLServer);
                    return("还原成功!");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
                finally
                {
                    oSQLServer.DisConnect();
                }
            }
            else if (dbtype.ToLower() == "dcsqlite")
            {
                try
                {
                    string sourcename = Request.MapPath("~/app_data") + "\\DcmsDataBase.db";
                    File.Copy(bakpath, sourcename, true);
                    return("还原成功!");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
            return("找不到源文件");
        }
Пример #2
0
        /// <summary>
        /// 备份数据库
        /// </summary>
        /// <returns>string</returns>
        private string doBackUp()
        {
            // return conn + "|" + dbname + "|" + dbuser + "|" + dbpwd;
            if (dbtype.ToLower() != "dcsqlite")
            {
                SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
                SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
                try
                {

                    string bakname = IRequest.GetFormString("BackUp_Name");
                    string bakpath = "";
                    if (bakname.Contains(".bak"))
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname;
                    }
                    else
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname + ".bak";
                    }
                    oSQLServer.LoginSecure = false;
                    oSQLServer.Connect(conn, dbuser, dbpwd);
                    oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
                    oBackup.Database = dbname;
                    oBackup.Files = bakpath;
                    oBackup.BackupSetName = bakname;
                    oBackup.BackupSetDescription = "数据库备份";
                    oBackup.Initialize = true;
                    oBackup.SQLBackup(oSQLServer);
                    return "备份成功!";

                }

                catch (Exception ex)
                {
                    return ex.Message;
                }
                finally
                {
                    oSQLServer.DisConnect();
                }
            }
            else if(dbtype.ToLower()=="dcsqlite")
            {
                try
                {
                    string sourcename=Request.MapPath("~/app_data")+"\\DcmsDataBase.db";
                    string bakname = IRequest.GetFormString("BackUp_Name");
                    string bakpath = "";
                    if (bakname.Contains(".db"))
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname;
                    }
                    else
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname + ".db";
                    }
                   // DirectoryInfo di = new DirectoryInfo(Request.MapPath("~/app_data"));
                    if(File.Exists(bakpath))//备份文件已存在
                    {
                        return "该备份文件已存在,请换个名称。";
                    }
                    File.Copy(sourcename, bakpath,false);
                    return "备份成功!";
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
            return "找不到源数据库文件,备份失败!";
        }
Пример #3
0
        /// <summary>
        /// 还原数据库
        /// </summary>
        /// <returns>string</returns>
        private string doRestore()
        {
            string bakname = IRequest.GetFormString("BackUp_File");
            string bakpath = Request.MapPath("~\\App_Data") + "\\" + bakname;
            if (dbtype.ToLower() != "dcsqlite")
            {
                SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
                SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
                try
                {
                    oSQLServer.LoginSecure = false;
                    oSQLServer.Connect(conn, dbuser, dbpwd);
                    oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
                    oRestore.Database = dbname;
                    oRestore.Files = bakpath;
                    oRestore.FileNumber = 1;
                    oRestore.ReplaceDatabase = true;
                    oRestore.SQLRestore(oSQLServer);
                    return "还原成功!";
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
                finally
                {
                    oSQLServer.DisConnect();
                }

            }
            else if (dbtype.ToLower() == "dcsqlite")
            {
                try
                {
                   string sourcename=Request.MapPath("~/app_data")+"\\DcmsDataBase.db";
                   File.Copy(bakpath, sourcename, true);
                   return "还原成功!";
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
            return "找不到源文件";
        }
Пример #4
0
        /// <summary>
        /// 备份数据库
        /// </summary>
        /// <returns>string</returns>
        private string doBackUp()
        {
            // return conn + "|" + dbname + "|" + dbuser + "|" + dbpwd;
            if (dbtype.ToLower() != "dcsqlite")
            {
                SQLDMO.Backup    oBackup    = new SQLDMO.BackupClass();
                SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
                try
                {
                    string bakname = IRequest.GetFormString("BackUp_Name");
                    string bakpath = "";
                    if (bakname.Contains(".bak"))
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname;
                    }
                    else
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname + ".bak";
                    }
                    oSQLServer.LoginSecure = false;
                    oSQLServer.Connect(conn, dbuser, dbpwd);
                    oBackup.Action               = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
                    oBackup.Database             = dbname;
                    oBackup.Files                = bakpath;
                    oBackup.BackupSetName        = bakname;
                    oBackup.BackupSetDescription = "数据库备份";
                    oBackup.Initialize           = true;
                    oBackup.SQLBackup(oSQLServer);
                    return("备份成功!");
                }

                catch (Exception ex)
                {
                    return(ex.Message);
                }
                finally
                {
                    oSQLServer.DisConnect();
                }
            }
            else if (dbtype.ToLower() == "dcsqlite")
            {
                try
                {
                    string sourcename = Request.MapPath("~/app_data") + "\\DcmsDataBase.db";
                    string bakname    = IRequest.GetFormString("BackUp_Name");
                    string bakpath    = "";
                    if (bakname.Contains(".db"))
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname;
                    }
                    else
                    {
                        bakpath = Request.MapPath("~/app_data") + "\\" + bakname + ".db";
                    }
                    // DirectoryInfo di = new DirectoryInfo(Request.MapPath("~/app_data"));
                    if (File.Exists(bakpath))//备份文件已存在
                    {
                        return("该备份文件已存在,请换个名称。");
                    }
                    File.Copy(sourcename, bakpath, false);
                    return("备份成功!");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
            return("找不到源数据库文件,备份失败!");
        }