Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot bulk load because the file could not be opened. Operating System Error Code 3

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

like image 301
user1345260 Avatar asked Oct 21 '13 10:10

user1345260


People also ask

Could not bulk load because the file could not be opened?

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.

Could not opened operating system error code 5?

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.

Could not be opened operating system error code 1326?

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.

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.


2 Answers

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'   ); 
like image 135
DuSant Avatar answered Sep 25 '22 18:09

DuSant


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.

like image 41
Jose Santos Avatar answered Sep 22 '22 18:09

Jose Santos