还原bak到localdb的问题:The logical database file cannot be found ldf
主要环境相关因素:win7,ms sql 2012,ms localdb,msms 2012.
步骤:
1,让DBA给一个bak文件到本地来做测试,DBA按自己的工作流程得到bak文件。
2,在msms 2012中创建同样名称的数据库,按我的想法设置mdf和ldf的路径。
3,,开始用上次已经成功过的脚本开始在msms 2012执行脚本。报错:
The logical database file cannot be found ldf,xxxx.ldf can't find。
首先说明为什么用脚本而不直接在管理器中通过UI还原,因为我这边安装完LocalDB后,它的master文件在c盘用户文件夹下面,导致总是会有不能访问master数据库的问题。在上次还原文件的时候,这个问题也折腾了一番,不过由于遇到的人多,马上就找到使用脚本的解决方案了。
没理由mdf文件可以找到,但是日志文件找不到啊。网上搜很久,最后有个 哥们说:
I'm having this problem too. I managed to deduce that it has something to do with the locations of the original data and log files. If you look at the file list you'll notice that the data and log files from the original database were stored in different locations. If the files were stored in the same location the restore would work successfully.
If you want to try this out restore the database in a full SQL Server 2012 instance (Standard or better) making sure the data and log files are stored in the same folder. Make a back-up of that database and restore it in your LocalDb instance. Now restore the same database on your full SQL Server instance placing the data and log files in separate folders, create a backup, and try to restore this in your LocalDb instance. You should get the same error message.
I've submitted feedback via Connect: https://connect.microsoft.com/SQLServer/feedback/details/789845.
以上说了两点:
1,本地新加数据库物理文件路径要保持和bak文件中的一致
即是bak中的文件名称和新数据库名称一致,同时bak文件中的mdf和ldf文件的路径和新数据库中的一致。这一点经过本人验证,只需要逻辑名一致就行了。物理路径和名称可以不一样。
如何查看bak文件物理和逻辑结构:
restore filelistonly
FROM DISK = 'D:\works\backup\web\xxx.bak'
2,mdf文件和log文件要在同一目录下。
而我这里为什么会出错的原因是,DBA把mdf放在data/*.mdf下,日志放在log/*.ldf下。更牛逼的是他在sql 2012 msms 操作总是成功,导致我没法怀疑他的操作。而在localdb中,它是从mdf来推断ldf路径的,所以总是找不到ldf文件。
最后让DBA把mdf,ldf放同一目录下问题搞定。
附上脚本:
--避免出现:
--Exclusive access could not be obtained because the database is in use
Alter Database SLdb
SET SINGLE_USER With ROLLBACK IMMEDIATE
RESTORE DATABASE dbname
FROM DISK = 'D:\works\backup\web\***.bak'
WITH REPLACE,
MOVE 'YYYY' TO 'D:\demos\Db\XXXX.mdf',
MOVE 'YYYY_log' TO 'D:\demos\Db\YYYY_log.ldf',
STATS = 1
GO
--再设置回来
alter database *****
set multi_user
还原bak到localdb的问题:The logical database file cannot be found ldf的更多相关文章
- sql server启动服务和还原bak文件
sql server启动服务和还原bak文件, sql server启动要: mysql数据库备份是psc后缀文件, sql server还原数据库备份bak文件: 三张图简介明了: ok:
- sql还原(.bak文件还原)
第一步: 右键“数据库”,选择“还原数据库” 第二步: 选择“设备”,然后选择“…” 第三步: 添加备份文件(这里使用MyDB.bak) 第四步: 勾选“还原”复选框,进度显示“已完成” 第五步: 最 ...
- 用SQL2000还原bak文件
1.右击SQL Server 2000实例下的“数据库”文件夹.就是master等数据库上一级的那个图标.选择“所有任务”,“还原数据库” 2.在“还原为数据库”中填上你希望恢 复的数据库名字.这个名 ...
- Sqlserver数据库还原.bak文件失败的两个问题
一.SQL Server数据库备份还原后,在数据库名称后会出现“受限制访问”字样 解决方案:将数据库限制访问改为:SINGLE_USER 数据库-->属性-->选项-->状 ...
- VS2010升级VS2012必备(MVC4 WebPage2.0 Razor2.0资料汇集)
刚把项目升级到2012,发现发生了很多变化,以下是最近看过的网站和资料汇集,供需要者参考. 本文在最近一个月可能会不断更新. Razor2.0 新特性介绍: 介绍1:http://vibrantcod ...
- 13 oracle数据库坏块-逻辑坏块(模拟/修复)
13 oracle数据库坏块-逻辑坏块 逻辑数据坏块的场景1)oracle bug也可能导致逻辑坏块的产生. 特别是parallel dml. 例如:Bug 5621677 Logical corru ...
- RMAN迁移数据库(不改变文件目录)
1.目标库创建相应目录mkdir -p /u01/app/oracle/oradata/orclmkdir -p /u01/app/oracle/fast_recovery_area/ORCLmkdi ...
- vs2012中使用localdb实例还原一个sql server 2008r2版本的数据库
use localdb sometime is easy than sql server ,and always use visual studio make you stupid. vs2012中还 ...
- RESTORE DATABASE命令还原SQLServer 数据库 bak
今天在sqlServer20005 的management studio里使用bak文件还原数据库的时候,总是失败!Restore failed for Server 'ADANDELI'. (Mi ...
随机推荐
- springMvc上传文件、读取zip/rar文件
参考文章: http://www.cnblogs.com/interdrp/p/6734033.html 方法一: 1)没有配置org.springframework.web.multipart.co ...
- mysql错误:Can’t create TCP/IP socket (10106) 解决方法
错误描述 “mysql错误:Can’t create TCP/IP socket (10106)”,目测是socket端口被占用的原因,然后在打开tomcat,报的错误中也包含了“socket”,再一 ...
- UI“三重天”之appium(一)
官方介绍: Appium is an open-source tool for automating native, mobile web, and hybrid applications on iO ...
- Repeater更具条件为每行数据背景填充颜色
后台代码 protected void RptPosterManager_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.I ...
- js中的event
event代表事件的状态,例如触发event对象的元素.鼠标的位置及状态.按下的键等等.event对象只在事件发生的过程中才有效.event的某些属性只对特定的事件有意义.比如,fromElement ...
- .net 架构
.net Webservice 三层架构,BLL(业务逻辑层),DAL(数据访问层)sql语句.MODEL模型层也就是实体层Entity(数据库字段和类的定义的映射). UI层(Web/Form)界面 ...
- SAFEARRAY
SAFEARRAY SafeArrayCreate SafeArrayDestroy // Specify the bounds: // -- dim. count = 2 // -- elemen ...
- C语言实现 读取写入ini文件实现(转)
#include <stdio.h> #include <string.h> /* * 函数名: GetIniKeyString * 入口参数: title * 配置文件中一组 ...
- EL 和 JSTL
EL 什么是EL表达式 EL(Express Lanuage) 表达式可以嵌入在jsp页面内部 减少jsp脚本的编写 EL出现的目的是要替代jsp页面中脚本的编写 作用区间 EL最主要的作用是获取四大 ...
- [udemy]WebDevelopment_CSS
Your First CSS(Cascading Style Sheets) Cascading means it always takes selector that is at the end 即 ...