Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What permissions are required to bulk insert in SQL Server from a network share with Windows authentication?

I am working on an application which bulk-loads data into a SQL Server 2008 database. It writes a CSV file to a network share then calls a stored procedure which contains a BULK INSERT command.

I'm migrating the application to what amounts to a completely new network. In this new world bulk insertion fails with this error:

Msg 4861, Level 16, State 1, Line 1
Cannot bulk load because the file "\\myserver\share\subfolder\filename" could not be opened. Operating system error code 5(failed to retrieve text for this error. Reason: 15105).

I connect to the database using Windows Authentication, using the same account which wrote the file. The file, and the folder in which it resides, grant read and modify rights both to my user account and the database server's domain service account. That service account apparently has constrained delegation permitted, which is mentioned on MSDN. Still no good. If I connect using a SQL Server account then bulk insertion succeeds, but we are trying to stick exclusively to Windows Authentication.

Does anybody have a handle on what needs to be done to make this work? How exactly does SQL Server go about accessing data on network shares, hopping between its service account and that of the connected user? I know that I can bulk insert in a similar situation in our current infrastructure, but it is so crufty with age that it would be hard to track down what has been done to enable this in the past.

like image 247
RobH Avatar asked Jun 27 '12 15:06

RobH


People also ask

What permissions are needed for bulk insert?

BULK INSERT requires Server Level Permissions and Database level Permissions. At server level, the respective login needs to have ADMINISTER BULK OPERATIONS permission (or be a member of the bulkadmin server role).

How do I grant bulk insert permissions in SQL Server?

To grant user ability to run Bulk Insert T-SQL command , login/user needs to be granted: BULKADMIN server role - or - ADMINISTER BULK OPERATIONS server-level permission. connect on target database. insert on target table.


1 Answers

Recently we had this issue for a number of our Devs. I've come up with a number of ways to allow testing of bulk inserts.

Our preference was to use a SQL service account. We set the SQL server and SQL agent to run as a service account and then allowed the devs to trigger agent jobs. The service account was granted permission to the UNC shares and this all functioned correctly. Note that the service account will always been fine running these agent jobs (assuming UNC permissions are set). It's the Devs trying to test that will come across these issues.

Another method is to create a share on the SQL server itself and point the bulk insert path at the local directory. These errors seem to only occur when accessing UNC paths. Regardless of whether the UNC path has the correct permissions to allow you access. For example we create C:\test\ as a folder on the SQL server itself and permission it to allow a dev to drop test files there. These are then called via the bulk insert command.

A command may need to be run against master to allow a SQL login group permission to bulk insert. This is as below.

GRANT ADMINISTER BULK OPERATIONS TO "domain\usergroup"
like image 150
n00borama Avatar answered Sep 22 '22 04:09

n00borama