0

I have executed the following query in my local system and its works fine for normal file (files that not have read only attribute). But, when I tried this for read only file the sql server prompts 'Access is Denied'.

    Declare @execmd varchar(150)
    SET @execmd= 'xp_cmdshell ''del "' + '\\DFSPath\000000045401.doc'+ '"''';
    Exec (@execmd)'

Property of the file to be delete SQL server error

Can anyone help me on this?

1 Answers1

0

The account that the SQL Server service is running under, does not have required access to the share, or does not have access to delete the file. Open up SQL Server Configuration Manager and update the service account to use an account that has the required access, and it should work.

Greg
  • 3,861
  • 3
  • 23
  • 58
  • Thanks for your reply. I verified with Administrator account but still no luck because the file was set to 'Read only'. Is there could be any issue on this? Could you please help me on this? – Mathivanan Sep 20 '19 at 11:25
  • Think about it. Open file explorer locally, mark a file read only, and try to delete it. – Greg Sep 20 '19 at 19:09
  • Thanks Greg for assisting me on this. – Mathivanan Sep 24 '19 at 13:58