OL.Common/DB/SQLServerBackupAndRestore.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace OL.Common.DB
{
    /// <summary>
    /// SQLServer备份还原
    /// </summary>
    public class SQLServerBackupAndRestore
    {
        /// <summary>
        /// 备份数据库
        /// </summary>
        /// <returns></returns>
        public static bool Backup(string filePath, string connectionString, string dataBaseName)
        {

            string sql = "backup database " + dataBaseName + " to disk='" + filePath + "'"; ;
            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            try
            {
                if (System.IO.File.Exists(filePath))
                {
                    return false;
                }
                SqlCommand com = new SqlCommand(sql, con);
                com.ExecuteNonQuery();
                //Response.Write(" "); 
                return true;
            }
            catch (Exception error)
            {
                return false;
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 还原数据库
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool Restore(string filePath, string connectionString, string dataBaseName)
        {
            string sql = "use master restore database " + dataBaseName + " from disk='" + filePath + "' WITH REPLACE";
            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            try
            {
                SqlCommand com = new SqlCommand(sql, con);
                com.ExecuteNonQuery();
                return true;
            }
后面还有 11 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。