- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一段恢复 SQL Server 数据库的 C# 代码。这很好用。问题是在另一个 .bak
文件上再次运行它。尽管第二个备份的名称不同,但它需要写入与第一个备份相同的目录,并且 .mdf
和 .ldf
的命名方案也相同文件。
我很好奇是否有办法修改 .mdf
和 .ldf
文件的命名方案,或者是否有其他方法可以创建这些文件要还原到的初始 SQL Server 目录下的子目录。
我目前收到的错误消息:
Additional information: The file XXXXXX.MDF cannot be overwritten. It is being used by database XAXAXAXAX
我想我可以使用一个移动语句,但我试图避免将所有目录值硬编码或记录在某处的配置中。
string sql = "SELECT database_id FROM sys.databases WHERE Name = '"+yuy+"'";
SqlConnection con = new SqlConnection(@"" + singleconn.Replace(@"\\", @"\"));
SqlCommand command = new SqlCommand(sql, con);
con.Open();
object resultObj = command.ExecuteScalar();
con.Close();
if (resultObj == null)
{
string sql2 = "Restore Database " + yuy + " FROM DISK = '" + @"\" + localdir.Replace(@"\\", @"\") + @"\" + FileName + "'";
SqlCommand command2 = new SqlCommand(sql2, con);
con.Open();
command2.ExecuteNonQuery();
con.Close();
con.Dispose();
File.Delete(@"\" + localdir.Replace(@"\\", @"\") + @"\" + FileName);
MessageBox.Show("Database recovered successfully!");
}
else
{
Random rnd = new Random();
int card = rnd.Next(52);
MessageBox.Show("There is already a database under this name; renaming the DB to " + yuy + card.ToString());
string sql2 = "Restore Database " + yuy + card.ToString() + " FROM DISK = '" + @"\" + localdir.Replace(@"\\", @"\") + @"\" + FileName + "'";
SqlCommand command2 = new SqlCommand(sql2, con);
con.Open();
command2.ExecuteNonQuery();
con.Close();
con.Dispose();
File.Delete(@"\" + localdir.Replace(@"\\", @"\") + @"\" + FileName);
MessageBox.Show("Database Recovered Successfully!");
}
多亏了 scsimon 解决了大部分问题,现在我得到的关于错误的最后一件事是这个。
附加信息:逻辑文件“XXXXXX.mdf”不是数据库“Databasename”的一部分。使用 RESTORE FILELISTONLY 列出逻辑文件名。
问题是我直接从数据库名称属性中提取它。任何帮助将不胜感激。
最佳答案
I'm just curious if there is a way to modify the naming scheme of the .mdf and .ldf files, or if there is some other method to create subdirs under the initial SQL Server directory for these files to be restored to.
您可以使用 MOVE
子句,如您在 RESTORE
命令中所建议的那样重命名 和/或移动 您的数据文件。它看起来像这样:
RESTORE DATABASE myDatabase FROM DISK = '\\somedir\someSubDir\mybackup.bak'
WITH
MOVE 'datafile1' TO 'E:\somedir\new_datafile2.mdf',
MOVE 'logfile' TO 'E\somedir\new_log.ldf'
这是为了将文件从备份中的默认位置移动到另一个目录(您可以这样做),但也可以重命名它们。当然,您也会对所有 .ndf
执行此操作。
I am trying to keep from needing all of the directory values hardcoded or logged in a config somewhere.
不用担心,只要restore带有 HEADERONLY
的数据库查看备份的内容,如名称、日期和其他有用信息。具体对于文件路径,您将使用 FILELISTONLY
.这将阻止您对它们进行硬编码。更多关于 here .
CREATE TABLE #DataFiles (LogicalName nvarchar(128)
,PhysicalName nvarchar(260)
,[Type] char(1)
,FileGroupName nvarchar(128) null
,Size numeric(20,0)
,MaxSize numeric(20,0)
,FileID bigint
,CreateLSN numeric(25,0)
,DropLSN numeric(25,0)
,UniqueID uniqueidentifier
,ReadOnlyLSN numeric(25,0) null
,ReadWriteLSN numeric(25,0) null
,BackupSizeInBytes bigint
,SourceBlockSize int
,FileGroupID int
,LogGroupGUID uniqueidentifier null
,DifferentialBaseLSN numeric(25,0) null
,DifferentialBaseGUID uniqueidentifier null
,IsReadOnly bit
,IsPresent bit
,TDEThumbprint varbinary(32) null
,SnapshotURL nvarchar(360) null
)
INSERT INTO #DataFiles
EXEC('RESTORE FILELISTONLY FROM DISK = ''E:\DB Backups\YourBackup.bak''')
SELECT LogicalName, PhysicalName FROM #DataFiles
DROP TABLE #DataFiles
关于c# - 如何还原多个对其 MDF 和 LDF 文件使用相同命名方案的 SQL Server 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54030313/
我以这种方式恢复了 merge 提交(功能->开发): git revert -m 1 git push origin develop 已创建新提交 Revert "Merge branch 'fe
我确信我得到了一个很好的答案 my previous question因为我之前从那些发帖的人那里得到了很多关于其他问题的帮助。 但我显然做错了什么,因为当我复制示例代码时,对象检查器向我显示的 My
我现在处于一个非常愚蠢的境地。使用 git-hub for windows 我已经恢复了我最近的两个本地提交,我无法撤消这个(恢复命令)。很多代码都没有了。是否可能恢复还原的提交?我是 git 的新手
我正在使用 TortoiseGit。我想恢复到删除几张图片之前的某个时间点。 我该怎么做,我看到的还原方法是不正确的.... 最佳答案 右键单击您的工作目录并从 TortoiseGit 菜单中选择显示
我们使用 Terraform 在 AWS 中创建所有资源。如果一切按计划进行,那将很方便。但是,我们确实必须考虑出现问题的时间。我们有一个问题是 RDS 实例。它由 Terraform 创建和跟踪。在
跟在后面有什么区别? (右键单击项目文件夹)更新到修订版 XXX (右击日志列表)恢复到这个版本 (右键单击日志列表)还原此修订版的更改 最佳答案 (右键单击项目文件夹)更新到修订版 XXX Your
我不知何故搞砸了我的观点,我想重置它们,但是重置按钮是灰色的。有谁知道会导致这种情况的原因吗? 我希望我有更多的信息,但我真的只知道这些。 最佳答案 转到窗口菜单 => 重置透视图。 编辑: 该选项可
我有一个具有多用户登录功能的应用程序。现在,我为登录功能创建了 redux 存储。如果用户登录,根据其类型,它将重定向到特定的仪表板。如果学生用户登录,他应该只能访问学生仪表板,他不应该能够访问其他仪
我已经恢复了一些更改。需要知道之前恢复的代码中的文件和更改(差异)。 最佳答案 是的,正如 ElpieKay 所说,您可以使用 git log --grep='Revert' 。 还有一个默认消息“
出现错误 ERROR in [at-loader] ./src/app/components/partials/userPartial.tsx:101:33 TS2339: Property 'lev
我不明白为什么主 JS 文件不想从 './actions' 导入 todo 而不带括号? todos from './reducers' 类似的情况,import 没有任何问题。 主 js 文件: i
我像这样以编程方式应用 AngularJS 过滤器: filtered = $filter('number')(value, 2); 这会给我类似 5,000.00 的东西。我需要一种方法来获取过滤后
我正在尝试在我的应用中实现 Redux。所以,我创建了 action、reducer、store 等……现在我必须将状态传递给 reducer 并更改此参数( bool 值)的值。我不知道我做错了什么
我有一个带有如下 DIV 的跨度: Here is my 现在我可以将我的内容设置为跨度,例如: $(.span.foo).text("This removed my inn
我也想将另一个数据库名称下的特定数据库还原到另一台服务器。到目前为止,还不错。 我使用了这个命令: pg_dump -U postgres -F c -O -b -f maindb.dump main
有没有办法回滚上次的提交,放到单独的分支中,以供以后测试?我做了一些我不想完全丢弃的更改,我只是想将它们放在不同的分支中以供进一步测试。 谁能帮我解决这个问题? 最佳答案 是的,您可以实现这一点 -
开发人员正在对两个文件进行小的更改。但是在这次提交期间,他遇到了 merge 冲突,删除了很多东西(可能没有最新的版本)。然后它被推送到共享仓库,其他一些开发人员做了一些其他提交。 现在,我们注意到
git revert 是如何使用的? 这听起来像是一个重复的问题,但当人们问它时,回答通常是,按照 Revert to a commit by a SHA hash in Git? 使用 git re
Cloudflare 已修复其免费开源 CDNJS 中的一个严重漏洞,该漏洞可能影响互联网上 12.7% 的网站。 CDNJS为数百万网站提供超过4000个JavaScript和CSS库,这些库公
为了安全起见,需要经常对数据库作备份,或者还原。对于 MySQL 而言,最方便的方法可能就是用 phpMyAdmin 的导出、导入功能了,但如果你的数据库体积比较大,作为 Web 应用的 phpMy
我是一名优秀的程序员,十分优秀!