I'm trying to set up a Stored Procedure as a SQL Server Agent Job and it's giving me the following error,
Cannot bulk load because the file "P:\file.csv" could not be opened. Operating system error code 3(failed to retrieve text for this error. Reason: 15105). [SQLSTATE 42000] (Error 4861)
Funny thing is the Stored Procedure works just fine when I execute it manually.
The drive P: is a shared drive on Windows SQL Server from LINUX via Samba Share and it was set up by executing the following command,
EXEC xp_cmdshell 'net use P: "\lnxusanfsd01\Data" Password /user:username /Persistent:Yes'
Any help on this would be highly appreciated
The reason that you receive this error message is that you are using SQL Server Authentication and the SQL Server hasn't accessed the bulk load folder. All you need to do is to give SQL Server access to the folder.
Error Code 5 is a Windows error code that appears when the user does not have sufficient permission to access the requested file or location. It appears when the software was denied access to a location for the purposes of saving, copying, opening, or loading files.
Error 1326 means "Logon failure: unknown user name or bad password." This error is raised because the IIS Service does not have any rights to use the named pipe. In order for a client to gain access to a Windows NT named pipe, the client needs to be validated by the Windows NT 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.
I dont know if you solved this issue, but i had same issue, if the instance is local you must check the permission to access the file, but if you are accessing from your computer to a server (remote access) you have to specify the path in the server, so that means to include the file in a server directory, that solved my case
example:
BULK INSERT Table FROM 'C:\bulk\usuarios_prueba.csv' -- This is server path not local WITH ( FIELDTERMINATOR =',', ROWTERMINATOR ='\n' );
To keep this simple, I just changed the directory from which I was importing the data to a local folder on the server.
I had the file located on a shared folder, I just copied my files to "c:\TEMP\Reports" on my server (updated the query to BULK INSERT from the new folder). The Agent task completed successfully :)
Finally after a long time I'm able to BULK Insert automatically via agent job.
Best regards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With