Cannot bulk load. Operating system error code 5 (Access is denied.)

后端 未结 12 1716
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 14:40

For some weird reason I\'m having problems executing a bulk insert.

BULK INSERT customer_stg
FROM \'C:\\Users\\Michael\\workspace\\pydb\\data\\andrew.out.txt\         


        
相关标签:
12条回答
  • 2020-12-02 15:15

    I had the same problem SSIS 2012 and the solution was to use Windows Authentication. I was using SQL authentication with the sa user.

    0 讨论(0)
  • 2020-12-02 15:17

    This error appears when you are using SQL Server Authentication and SQL Server is not allowed to access the bulk load folder.

    So giving SQL server access to the folder will solve the issue. enter image description here

    Here is how to: Go to the folder right click ->properties->Security tab->Edit->Add(on the new window) ->Advanced -> Find Now. Under the users list in the search results, find something like SQLServerMSSQLUser$UserName$SQLExpress and click ok, to all the dialogs opened.

    0 讨论(0)
  • 2020-12-02 15:19

    I have come to similar question when I execute the bulk insert in SSMS it's working but it failed and returned with "Operation system failure code 5" when converting the task into SQL Server Agent.

    After browsing lots of solutions posted previously, this way solved my problem by granting the NT SERVER/SQLSERVERAGENT with the 'full control" access right to the source folder. Hope it would bring some light to these people who are still struggling with the error message.

    0 讨论(0)
  • 2020-12-02 15:21

    Try giving the folder(s) containing the CSV and Format File read permissions for ‘MSSQLSERVER’ user (or whatever user the SQL Server service is set to Log On As in Windows Services)

    0 讨论(0)
  • 2020-12-02 15:28

    Make sure the file you're using ('C:\Users\Michael\workspace\pydb\data\andrew.out.txt') is on the SQL server machine and not the client machine running MSSMS.

    0 讨论(0)
  • 2020-12-02 15:28

    In our case it ended up being a Kerberos issue. I followed the steps in this article to resolve the issue: https://techcommunity.microsoft.com/t5/SQL-Server-Support/Bulk-Insert-and-Kerberos/ba-p/317304.

    It came down to configuring delegation on the machine account of the SQL Server where the BULK INSERT statement is running. The machine account needs to be able to delegate via the "cifs" service to the file server where the files are located. If you are using constrained delegation make sure to specify "Use any authenication protocol".

    If DFS is involved you can execute the following Powershell command to get the name of the file server:

    Get-DfsnFolderTarget -Path "\\dfsnamespace\share"
    
    0 讨论(0)
提交回复
热议问题