BULK INSERT returns error “Access is denied”

Deadly 提交于 2019-12-11 11:48:39

问题


When running Bulk Insert

BULK INSERT MyDatabase.dbo.MyTable 
FROM '\\Mylaptop\UniversalShare\SQLRuleOutput.csv' 
WITH (FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')

on a remote SQL Server I get this error:

"Cannot bulk load because the file "\MyLaptop\UniversalShare\SQLRuleOutput.csv" could not be opened. Operating system error code 5(Access is denied.)."

  • The share is open to all.
  • I have run PowerShell Invoke-SQLCMD scripts on that SQL Server that where it connects to that same share, so the server can see the share.
  • This Bulk Insert statement fails with the same error whether I run it directly as T-SQL on the SQL Server, or through PowerShell Invoke-SQLCMD (which is my intended method).

This question is similar, Cannot bulk load. Operating system error code 5 (Access is denied.), but in my case the share is open to all, so permissions shouldn't be an issue, and the share is definitely in a different place (my laptop for POC development) than SQL Server.

Does anyone know why this error is happening, or how to get around it?

Thanks,

Conrad


回答1:


The share must be accessible to the Windows account that the MSSQL Service is running under; typically Local System or Network Service (but could be anything). Its unlikely you have explcitly granted access to MYSERVER\LOCAL SERVICE to your local file share.

Running Powershell Invoke-SQLCMD doesn't demonstrate that the MSSQL service has rights to your drive - it depends what account you are running power shell as.



来源:https://stackoverflow.com/questions/49245434/bulk-insert-returns-error-access-is-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!