Cannot bulk load. The file "csv" does not exist or you don't have file access rights -- Azure

4.1k views Asked by At

I am trying to import a file from my Azure blob storage into Azure managed instance.

So first I created a extrenal data source

CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage
WITH (  TYPE = BLOB_STORAGE, 
        LOCATION = 'https://abcd.blob.core.windows.net/testFolder/', 
);

then uploaded my csv file into blob storage

When I tried to query csv file,

SELECT * FROM OPENROWSET(
   BULK  'product.csv',
   DATA_SOURCE = 'MyAzureBlobStorage',
   SINGLE_CLOB) AS DataFile;

I got,

Msg 4860, Level 16, State 1, Line 99 Cannot bulk load. The file "product.csv" does not exist or you don't have file access rights.

Can somebody help me to identify whats the issue here ?

1

There are 1 answers

1
Alberto Morillo On

Please verify the Shared Access Signature start and expiry date and time. Set the start date to any day last week. Verify "Allowed IP addresses" field is blank.

The SAS (Shared Access Signature) is a string that is created as follows:

  1. In Azure portal, go to your storage account
  2. Press Shared Access Signature
  3. Fill in fields (make sure your start date is a few days prior, and you can leave Allowed IP addresses blank)
  4. Press Generate SAS
  5. Copy the string in the SAS Token field
  6. Remove the leading ? before pasting it into your SQL script

Below a sample script.

CREATE DATABASE SCOPED CREDENTIAL BlobCredential
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = 'sv=SAS_TOKEN_HERE';


CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage
WITH (  TYPE = BLOB_STORAGE, 
        LOCATION = 'https://abcd.blob.core.windows.net/testFolder/',
CREDENTIAL = BlobCredential 
);