Why can't I read from .BAK files on my Desktop using SQL Express in Windows Authentication Mode

大城市里の小女人 提交于 2019-12-11 07:38:53

问题


I am trying to execute this SQL query prior to restoring a .BAK file in SQL Express. Initially, I had the file on the Desktop of my user account. I am logged in as Administrator.

When I try to access the .BAK file on the desktop like this

RESTORE FILELISTONLY FROM DISK= 'C:\Documents and Settings\Administrator\Desktop\file.bak'

I get an error.

Msg 3201, Level 16, State 2, Line 1
Cannot open backup device 'C:\Documents and Settings\Administrator\Desktop\file.bak'. Operating system error 5(Access is denied.).
Msg 3013, Level 16, State 1, Line 1
RESTORE FILELIST is terminating abnormally.

However, when I move the .BAK file to C:\temp, and execute this

RESTORE FILELISTONLY FROM DISK= 'C:\temp\file.bak'

It works just fine.

I cant figure out what is going on. Is there a way to access files on Desktop using Windows Authentication with SQL Express?


回答1:


Try granting read permission to Users or LOCAL SERVICE to the folder C:\Documents and Settings\Administrator\Desktop\ in your Policy Editor (right click the folder and in the Security tab click Add... then Advanced...|Find Now




回答2:


When you are running the restore script, it is executing under the context of the service account that the SQL Express is running under. Go to the Services Management Console ( or run Services.msc) and find the SQL Express service and look at what account it is configured to run under and then look at the permissions of the file on your desktop and make sure that account has read access.




回答3:


after SQL Server 2008R2 SP1 you don't need to Go to the Services Management Console ( or run Services.msc) to find out the account under which the sql server service is running.

simply use the code below:

select * from
sys.dm_server_services

SELECT  DSS.servicename,
        DSS.startup_type_desc,
        DSS.status_desc,
        DSS.last_startup_time,
        DSS.service_account,
        DSS.is_clustered,
        DSS.cluster_nodename,
        DSS.filename,
        DSS.startup_type,
        DSS.status,
        DSS.process_id
FROM    sys.dm_server_services AS DSS;


来源:https://stackoverflow.com/questions/242421/why-cant-i-read-from-bak-files-on-my-desktop-using-sql-express-in-windows-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!