[英]Azure blob to Azure SQL Database: Cannot bulk load because the file "xxxx.csv" could not be opened. Operating system error code 5(Access is denied.)
I am trying to bulk load in azure sql database some data in an azure blob storage.我正在尝试在 azure sql 数据库中批量加载 azure blob 存储中的一些数据。 The file content is:
文件内容为:
customer,age,gender
'C1093826151','4','M'
'C352968107','2','M'
'C2054744914','4','F'
the file is in a container called silver .该文件位于名为silver的容器中。 in the silver container I have the File1.fmt which content is:
在银色容器中,我有 File1.fmt 内容是:
14.0
3
1 SQLCHAR 0 7 "," 1 customer ""
2 SQLCHAR 0 100 "," 2 age SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 100 "\r\n" 3 gender SQL_Latin1_General_CP1_CI_AS
I have the extra line add the end of the fmt file.我有额外的行添加 fmt 文件的末尾。
I have created a SAS token will all enabled and allowed like the screenshot below:我创建了一个 SAS 令牌,将全部启用并允许,如下面的屏幕截图所示:
The firewall rules on datalake are as the picture below: datalake上的防火墙规则如下图:
Below are my sql scripts (I removed the? at the beginning of the SAS token, as my silver container is public, I know I should need the SAS token):下面是我的 sql 脚本(我删除了 SAS 令牌开头的?,因为我的银容器是公开的,我知道我应该需要 SAS 令牌):
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'safepassword';
go
DROP EXTERNAL DATA SOURCE MyAzureInvoices
DROP DATABASE SCOPED CREDENTIAL UploadInvoices
CREATE DATABASE SCOPED CREDENTIAL UploadInvoices
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = 'sv=2019-12-12**********************************88%3D'; -- dl
--DROP EXTERNAL DATA SOURCE MyAzureInvoices
CREATE EXTERNAL DATA SOURCE MyAzureInvoices
WITH (
TYPE = BLOB_STORAGE,
LOCATION = 'https://mydatalake.blob.core.windows.net/silver',
CREDENTIAL = UploadInvoices
);
Landing table:着陆表:
CREATE TABLE [ext].[customer](
[customer_id] [int] IDENTITY(1,1) NOT NULL,
[customer] [varchar](100) NOT NULL,
[age] [int] NOT NULL,
[gender] [varchar](50) NOT NULL
) ON [PRIMARY]
GO
and these are the ways I tried to load the file into the sql database:这些是我尝试将文件加载到 sql 数据库的方法:
-- 1
SELECT * FROM OPENROWSET(
BULK 'bs140513_032310-demo.csv',
DATA_SOURCE = 'MyAzureInvoices',
FORMAT = 'CSV',
FORMATFILE='File1.fmt',
FORMATFILE_DATA_SOURCE = 'MyAzureInvoices'
) AS DataFile;
-- 2
go
SELECT * FROM OPENROWSET(
BULK 'bs140513_032310-demo.csv',
DATA_SOURCE = 'MyAzureInvoices',
SINGLE_CLOB) AS DataFile;
go
-- 3
BULK INSERT ext.customer
FROM 'bs140513_032310-demo.csv'
WITH (
DATA_SOURCE = 'MyAzureInvoices', FORMAT = 'CSV' );
They all give the same error:他们都给出了同样的错误:
Msg 4861, Level 16, State 1, Line 2
Cannot bulk load because the file "bs140513_032310-demo.csv" could not be opened. Operating system error code 5(Access is denied.).
I have tried for 3 days and I am lost.我已经尝试了 3 天,但我迷路了。 Thanks for your help NB:
感谢您的帮助注意:
While being disconnected, it can access the files:断开连接时,它可以访问文件:
* *
mydatalake is fake, but I can access with the real name mydatalake是假的,但我可以实名访问
I think this error message is misleading.我认为此错误消息具有误导性。
I've created a same test as you, and encountered the same error.我创建了与您相同的测试,并遇到了相同的错误。
But after I edited the bs140513_032310-demo.csv
and File1.fmt
, it works well.但是在我编辑
bs140513_032310-demo.csv
和File1.fmt
,它运行良好。
I changed the bs140513_032310-demo.csv
like this:我像这样更改了
bs140513_032310-demo.csv
:
I changed the File1.fmt
like this, I changed the cutomer column length from 7 to 100 and age column length from 100 to 7:我像这样更改了
File1.fmt
,我将 cutomer列长度从 7 更改为 100,将age 列长度从 100 更改为 7:
14.0
3
1 SQLCHAR 0 100 "," 1 customer ""
2 SQLCHAR 0 7 "," 2 age SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 100 "\r\n" 3 gender ""
SELECT * FROM OPENROWSET(
BULK 'bs140513_032310-demo.csv',
DATA_SOURCE = 'MyAzureInvoices',
FORMAT = 'CSV',
FORMATFILE='File1.fmt',
FORMATFILE_DATA_SOURCE = 'MyAzureInvoices'
) AS DataFile;
INSERT into ext.customer_Staging with (TABLOCK) (customer, age, gender)
SELECT * FROM OPENROWSET(
BULK 'bs140513_032310-demo.csv',
DATA_SOURCE = 'MyAzureInvoices',
FORMAT = 'CSV',
FORMATFILE='File1.fmt',
FORMATFILE_DATA_SOURCE = 'MyAzureInvoices'
) AS DataFile;
go
INSERT INTO ext.customer(Name, Address)
SELECT customer, age, gender
FROM ext.customer_Staging
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.