Share via

Azure bulk load sql from Cannot bulk load file could not be opened. error code 32 used by another process

Bill S iii 0 Reputation points
2023-10-20T15:45:43.69+00:00

Not sure why I'm getting this error?

Msg 4861, Level 16, State 1, Line 8

Cannot bulk load because the file "sta/arinvt_class.csv" could not be opened. Operating system error code 32(The process cannot access the file because it is being used by another process.).

create external data source

DROP EXTERNAL DATA SOURCE WWSAzureBlob; 
CREATE EXTERNAL DATA SOURCE WWSAzureBlob 
WITH (  
  TYPE = BlOB_STORAGE, 
    LOCATION   = 'Shared access signature blob service SAS URl' 
);
Bulk insert script
--drop procedure LoadData;
CREATE  PROCEDURE LoadData
AS
BEGIN
DELETE FROM stage.arinvt_class;
BULK INSERT stage.arinvt_class
FROM 'sta/arinvt_class.csv'
WITH ( 
    DATA_SOURCE = 'WWSAzureBlob',
    FORMAT      = 'CSV',
    FIRSTROW    = 2
);
END

SAS key definition

attached screen shot of SAS key creating parameters

Azure SQL Database
Azure
Azure

A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.


1 answer

Sort by: Most helpful
  1. Alberto Morillo 35,506 Reputation points MVP Volunteer Moderator
    2023-10-20T16:02:05.8333333+00:00

    Based on my experience that error Msg 4861 is related to the location that cannot be found. Try creating the External Data Source as shown below:

    CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage
     WITH ( TYPE = BLOB_STORAGE,
            LOCATION = 'https://myazureblobstorage.blob.core.windows.net',
            CREDENTIAL= MyAzureBlobStorageCredential);
    GO
    BULK INSERT Product FROM 'sta/arinvt_class.csv' WITH (DATA_SOURCE = 'MyAzureBlobStorage', FORMAT='CSV', CODEPAGE = 65001, --UTF-8 encoding 		FIRSTROW=2, ROWTERMINATOR = '0x0a', TABLOCK);
    
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.