我正在尝试将平面文件从 Blob 存储批量插入到 SQL Server 数据库。这是我所做的:
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'XYZ'
CREATE DATABASE SCOPED CREDENTIAL ohhyeaa
WITH IDENTITY = 'SHARED ACCESS SIGNATURE'
SECRET = 'access policy key from the entire container'
IF EXISTS ( SELECT * FROM sys.external_data_sources)
DROP EXTERNAL DATA SOURCE MyAzureBlobStorage
CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage
WITH ( TYPE = BLOB_STORAGE, LOCATION = 'CONTAINERaccount.blob.core.windows.net/load-to-sql', CREDENTIAL= MyAzureBlobStorageCredential)
文件已加载到容器中
执行:
BULK INSERT [dbo].file.csv
FROM 'StagingFolder_DataToSQL/project/date/file.csv'
WITH (FORMAT = 'CSV', FIRSTROW = 2, FIELDTERMINATOR = '|',
KEEPIDENTITY, DATA_SOURCE = 'MyAzureBlobStorage', batchsize = 300000)
这给了我以下错误:
消息 4860,级别 16,状态 1,第 1 行无法批量加载。文件 “StagingFolder_DataToSQL ///.csv”不存在 或者您没有文件访问权限。
我是服务器和加载数据的特定数据库的所有者。
我需要在 Azure 门户中定义访问设置以允许加载文件吗?
我在不同的 Azure 环境中成功完成了此过程,并且效果很好。非常感谢您的帮助。谢谢!
无法批量加载。文件“StagingFolder_DataToSQL///.csv”不存在或您没有文件访问权限。
错误原因是您使用的访问令牌对应加载的对象没有读取权限,或者文件路径不正确/不存在文件路径区分大小写。
获取具有适当权限的容器范围的 SAS 令牌:
我的SQL代码:
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'strong_password'
CREATE DATABASE SCOPED CREDENTIAL ohhyeaa7
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = 'Container_scoped_SAS_token'
IF EXISTS ( SELECT * FROM sys.external_data_sources)
DROP EXTERNAL DATA SOURCE MyAzureBlobStorage
CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage
WITH ( TYPE = BLOB_STORAGE, LOCATION = 'https://<Storage_Account_name>.blob.core.windows.net/<Container_name>', CREDENTIAL= ohhyeaa7)
BULK INSERT dbo.student
FROM 'stagged/sample/file3.csv'
WITH (FORMAT = 'CSV', FIRSTROW = 2, FIELDTERMINATOR = ',',
KEEPIDENTITY, DATA_SOURCE = 'MyAzureBlobStorage', batchsize = 300000)