Share via

BULK INSERT cannot access UNC path, error code 5 (Access is denied) using gMSA unless locally triggered

Michelle 0 Reputation points
2026-04-28T02:03:11.9766667+00:00

Running a stored procedure to bulk insert from a UNC path works locally via SSMS and via SQL agent job but if run remotely I receive Operating system error code 5 (access is denied). Please help as this workaround is not suitable for our environment.

Environment is SQL Server 2022 Standard Edition RTM-CU24 (16.0.4245.2)

Symptoms:

  • BULK INSERT fails with Operating system error code 5 (Access is denied) on UNC path
  • xp_cmdshell accessing identical UNC path as same gMSA succeeds
  • OPENROWSET(BULK) fails with same error
  • Works when SSMS is run locally on SQL Server
  • Works when executed via SQL Agent job
  • No cifs/ service ticket for target file server is requested during BULK INSERT
  • Manually pre-caching cifs/FILESERVER ticket via xp_cmdshell pushd does not resolve the issue

Confirmed working:

  • gMSA Test-ADServiceAccount returns True
  • NTFS and share ACLs grant gMSA Full Control
  • cifs/ SPNs exist on both SQL Server (MSSQLSvc) and file server
  • Constrained delegation configured on gMSA for cifs/ of file server and DFS namespace servers
  • Client to SQL connection confirmed Kerberos (not NTLM)
  • ad hoc distributed queries enabled
  • allow filesystem enumeration enabled
  • xp_cmdshell can list and access the file as gMSA
  • Local file BULK INSERT works fine

What was tried:

  • Trace flags 4616, 4032 - nothing of interest logged
  • Constrained delegation configuration
  • cifs SPNs were absent and manually added to file server
  • Pre-cached Kerberos ticket before BULK INSERT

Thanks

SQL Server | SQL Server Transact-SQL

Answer recommended by moderator

Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
2026-05-12T20:43:58.1766667+00:00

So I played a little with this. If I first verified that delegation worked for a linked server. That is, I was running SSMS on server A, connected to server B and ran a linked-server query against server C. That worked. Then I tried to run BULK INSERT against a file on a share on server C. That did not work, but I got the same error as Michelle.

Out of curiosity, I asked around "Is this supposed to work?", and I got this answer from a contact at Microsoft:

Yeah, this is expected, it’s really more about Kerberos delegation for file shares than anything specific to BULK INSERT. What’s happening is the classic double-hop: you connect from A to B, and then B tries to access C on your behalf. Whether that works depends on which services on C are allowed for delegation. In your setup, B is talking to two different services on C:

  • SQL Server (via the linked server)
  • The file share (via SMB for BULK INSERT) Delegation is already set up for SQL Server on C, which is why the SELECT works. The file share isn’t included, so when BULK INSERT tries to open the file as you, it gets denied. To change it, you just need to update delegation on the SQL Server service account on B and add the file service for C. You should end up with both:
  • MSSQLSvc/C.fqdn:1433 (or your instance/port)
  • cifs/C.fqdn (or HOST/C.fqdn) A couple things to keep in mind:
  • Constrained delegation still respects the user’s permissions on C.
  • If A -> B isn’t already using Kerberos, you may need “Use any authentication protocol.”
  • Make sure the user isn’t marked as “sensitive and cannot be delegated.” The behavior should be the same independent of SQL version. Yeah, this is expected, it’s really more about Kerberos delegation for file shares than anything specific to BULK INSERT. What’s happening is the classic double-hop: you connect from A to B, and then B tries to access C on your behalf. Whether that works depends on which services on C are allowed for delegation. In your setup, B is talking to two different services on C:
  • SQL Server (via the linked server)
  • The file share (via SMB for BULK INSERT) Delegation is already set up for SQL Server on C, which is why the SELECT works. The file share isn’t included, so when BULK INSERT tries to open the file as you, it gets denied. To change it, you just need to update delegation on the SQL Server service account on B and add the file service for C. You should end up with both:
  • MSSQLSvc/C.fqdn:1433 (or your instance/port)
  • cifs/C.fqdn (or HOST/C.fqdn) A couple things to keep in mind:
  • Constrained delegation still respects the user’s permissions on C.
  • If A -> B isn’t already using Kerberos, you may need “Use any authentication protocol.”
  • Make sure the user isn’t marked as “sensitive and cannot be delegated.” The behavior should be the same independent of SQL version.

I understand from your original post that you have more or less tried this already, but maybe you have missed something somewhere.

No, I did not try this myself. I don't know if I have the rights to play with delegation, but even if I have it is definitely outside the scope from what I am supposed to do on these servers. (I'm not a DBA; but a systems developer.) However, my gut feeling is that, yes, you can do this with BULK INSERT if you configure everything correctly. The reason I think so is that I expect this to be a common thing that people want to do. So if it does not work at all, I would expect to see more questions about it.

I hope you have followed our advice to open a support case, and maybe the issue is already resolved by now. But I still wanted to make this update.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Akhil Gajavelly 1,830 Reputation points Microsoft External Staff Moderator
    2026-04-28T04:10:52.9033333+00:00

    Hi @Michelle ,

    This doesn't look like a permission or gMSA issue your xp_cmdshell test already proves the account can access the share. The real issue is that BULK INSERT uses the impersonated remote client's security token for file I/O, not the gMSA's OS-level Kerberos session. That token is a non-forwardable network logon token, so no CIFS ticket is even negotiated hence the error code 5. That's why local execution and SQL Agent (no delegation needed) both work fine.

    Try bellow few Practical options.

    • SQL Agent job via sp_start_job wraps the procedure, avoids the hop
    • BCP via xp_cmdshell since you've confirmed xp_cmdshell works, BCP runs as a real OS process under the gMSA and sidesteps the thread impersonation issue entirely
    • RBCD on the file server configure Resource-Based Constrained Delegation on the file server computer object to trust the SQL gMSA, and ensure TrustedToAuthForDelegation is set on the gMSA for protocol transition (S4U2Self). This is the clean fix if you want BULK INSERT to work as-is without workarounds.

    Thanks,
    Akhil.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.