问题
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 PowerShellInvoke-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