I tried to execute a simple .sql script from the command prompt and this is the output I got

C:\Users\Administrator>sqlcmd -S {machine name}\SQLEXPRESS -i C:/SqlScripts/UpdateStat.sql
Sqlcmd: Error: Error occurred while opening or operating on file C: (Reason: Access is denied).

I opened cmd under admin mode and got the same result. Checked C drive permission and Admin has full access.

Running on Windows Server 2012R2

  • 1
    Is this UpdateStat.sql the only affected script? Can you execute another script from this location? – McNets Jun 19 '17 at 7:06
  • 1
    Have you tried changing C:/SqlScripts/UpdateStat.sql to C:\SqlScripts\UpdateStat.sql ? – joanolo Jun 19 '17 at 7:31
  • @McNets nope cant execute any of the scripts – Steve Jun 19 '17 at 21:51
  • @joanolo tried that, no luck – Steve Jun 19 '17 at 21:51
  • Could you try to add read/write permission to NT AUTHORITY\SYSTEM user on c:\folder? – McNets Jun 19 '17 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.