/// <summary> /// 备份数据库 /// </summary> /// <param name="DBName">数据库名称</param> /// <param name="newDBName">备份数据库名称</param> /// <param name="path">备份路径</param> public static bool BackUpDatabase(string DBName, string newDBName, string path) { Debug.Assert(DBName != "" || DBName != null, "Invalid DBName,please check it and try again"); Debug.Assert(path != "" || path != null, "Invalid file Path,please check it and try again"); if (!path.EndsWith("\\")) { path += "\\"; } using (SqlConnection con = SqlBase.GetConnection()) { con.Open(); if (System.IO.File.Exists(path + newDBName + ".dat")) { System.IO.File.Delete(path + newDBName + ".dat"); } SqlBase.ExecuteQuery("BACKUP DATABASE " + DBName + " TO DISK = '" + path + newDBName + ".dat'", CommandType.Text); return(true); } }