• HanShi - Wednesday, February 21, 2018 1:11 PM

    wak_no1 - Wednesday, February 21, 2018 11:14 AM

    I'm getting: Sqlcmd: Error: Error occurred while opening or operating on file \\servername\C$\directory\test.sql (Reason: Access is denied).

    The service account that's running sql has full read/write permissions on the share, I have full read/write permissions too but still get the error. I've verified the directory/file too.

    What other possible causes could there be?

    If you are running the code from a SQL Agent job, you'll need to grant permissions on the folder to the SQL Agent service account. That could well be another account than the SQL Server service account.
    Another option is to create credentials and use that to run the job (or jobstep).

    I'm running it as me, i'm an admin on the server. I've also added the SQL Agent service account as admin but still get the error.