![](/img/trans.png)
[英]The semaphore timeout period has expired while restoring .bak file in SQL Server Management Studio
[英]SQL Server Management Studio - trouble restoring from bak and trn
我正在尝试从.bak
和trn
文件还原数据库。 我无法通过SQL Server Management Studio查看.bak
和.trn
文件。 但是当我转到文件夹时,我看到了它们。 我使用了T-sql,但是它说访问被拒绝。 我是服务器上的系统管理员。 有人可以帮我吗。 脚本:
从磁盘还原数据库[XYZ] = N'R:\\ MSSQL10_50.MSSQLSERVER \\ MSSQL \\ Restore \\ XYZ_Full.bak'WITH FILE = 1
走
错误:消息3201,级别16,状态2,第3行无法打开备份设备'R:...”操作系统错误5(访问被拒绝。)。
确保您在SSMS中的帐户(Windows或sql服务器)有权备份/还原,sysadmin,db_backoperator等。
备份和还原过程在SQL Server(引擎)服务帐户下运行,因为您可能正在便携式计算机上运行SSMS,但正在使用服务器上的文件。
无论以谁身份登录,都是需要访问目录和文件的服务帐户。
服务帐户是域帐户还是本地服务? 我使用域帐户,以便可以处理UNC路径上的文件。
另外,在浏览对话框期间将执行两个系统存储过程: master.dbo.xp_dirtree,master.dbo.xp_fileexist 。
如果它们从查询窗口返回空结果,则说明SQL Server服务帐户存在权限问题。
Profiler跟踪浏览操作(Adventure Works)。
declare @Path nvarchar(255)
declare @Name nvarchar(255)
select @Path = N'C:\mssql\save me\backup\AdventureWorks2012'
select @Name = N'AdventureWorks2012_backup_2012_11_30_160723_2147507.bak'
create table #filetmpfin (Name nvarchar(255) NOT NULL, IsFile bit NULL)
if(@Name is null)
begin
create table #filetmp (Name nvarchar(255) NOT NULL, depth int NOT NULL, IsFile bit NULL )
insert #filetmp EXECUTE master.dbo.xp_dirtree @Path, 1, 1
insert #filetmpfin select Name, IsFile from #filetmp f
drop table #filetmp
end
if(NOT @Name is null)
begin
declare @FullName nvarchar(300)
if(@Path is null)
select @FullName = @Name
else
select @FullName = @Path + '\' + @Name
create table #filetmp2 ( Exist bit NOT NULL, IsDir bit NOT NULL, DirExist bit NULL )
insert #filetmp2 EXECUTE master.dbo.xp_fileexist @FullName
insert #filetmpfin select @Name, 1-IsDir from #filetmp2 where Exist = 1 or IsDir = 1
drop table #filetmp2
end
SELECT
Name AS [Name],
IsFile AS [IsFile]
FROM
#filetmpfin
ORDER BY
[IsFile] ASC,[Name] ASC
drop table #filetmpfin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.