1

Following this announcement https://azure.microsoft.com/en-gb/updates/preview-loading-files-from-azure-blob-storage-into-sql-database/

I tried the example as such provided in this GitHub sample and receiving the following error,

-- Create credential with Azure Blob SAS
CREATE DATABASE SCOPED CREDENTIAL xxxstorcred
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = '?sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdl&st=2017-03-14T17%3A52%3A00Z&se=2017-05-31T16%3A52%3A00Z&sig=f45435435TzrsdsdsdC8wonjDMBG0T0GJj717XetLEWReZ64eOrQE%3D';

-- Create external data source with with the roow URL of the Blob storage Account and associated credential.
CREATE EXTERNAL DATA SOURCE xxxstor
WITH (  TYPE = BLOB_STORAGE, 
        LOCATION = 'https://xxxstor.blob.core.windows.net', 
        CREDENTIAL= xxxstorcred);
--CREATE DESTINATION TABLE (if not exists)
DROP TABLE IF EXISTS Product;
GO

CREATE TABLE dbo.Product(
    Name nvarchar(50) NOT NULL,
    Color nvarchar(15) NULL,
    Price money NOT NULL,
    Size nvarchar(5) NULL,
    Quantity int NULL,
    Data nvarchar(4000) NULL,
    Tags nvarchar(4000) NULL
)
GO

--LOAD

-- INSERT CSV file into Product table
BULK INSERT Product
FROM 'random/product.csv' --random is the container name
WITH (  DATA_SOURCE = 'xxxstor',
        FORMAT='CSV', CODEPAGE = 65001, --UTF-8 encoding
        FIRSTROW=2,
        TABLOCK); 

Cannot bulk load because the file "random/product.csv" could not be opened. Operating system error code 1117(The request could not be performed because of an I/O device error.).

What am I missing?

2 Answers 2

3

I have tried the t-sql from the github sample that you provide. It works fine. From my test, there are two possibilities that will cause this error:

1) The container name is incorrect

2) the SAS SECRET is incorrect

Based on your description, I think your SAS secret is incorrect. Here is the secret that you used:

SECRET = '?sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdl&st=2017-03-14T17%3A52%3A00Z&se=2017-05-31T16%3A52%3A00Z&sig=f45435435TzrsdsdsdC8wonjDMBG0T0GJj717XetLEWReZ64eOrQE%3D';

As my test, we need to remove '?'. Please try below secret:

SECRET = 'sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdl&st=2017-03-14T17%3A52%3A00Z&se=2017-05-31T16%3A52%3A00Z&sig=f45435435TzrsdsdsdC8wonjDMBG0T0GJj717XetLEWReZ64eOrQE%3D';

For how to generate SAS, please refer to this article.

3
  • Also, in order to avoid potential format, encoding, or other issues, try to load entire file as a single text to verify that it can be accessed: SELECT * FROM OPENROWSET(BULK 'random/product.csv', DATA_SOURCE = datasourcename', SINGLE_CLOB) as data
    – Jovan MSFT
    Mar 15, 2017 at 17:39
  • Yes its indeed the leading "?" in the SAS SECRET. Once removed it works fine. Thanks for reply.
    – databash
    Mar 16, 2017 at 11:58
  • SAS is supposed to have an expiration time, after that, do I have to update the scoped credential?
    – dduque
    Oct 7, 2020 at 16:02
3

In my case it was a different problem with SAS Token: it was not valid yet.

I created a token with a default start date (which is the current time in my current time zone). But then it is being evaluated against GMT, which is behind my time.

You can easily test SAS token in Microsoft Azure Storege Explorer. In such case it will show a message like this: Image is showing error message from Azure Storage Explorer saying "Signature not valid in the specified time frame"

The solution is to modify the start time e.g. to 00:00:00.

1
  • Good finding @Jakub that was my issue too :-)
    – tjeuten
    Nov 6, 2017 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.