从 SQL Server 2025 (17.x) 预览版开始,可以使用托管标识访问:
- Microsoft Azure Blob 存储
- Microsoft Azure Data Lake
先决条件
- SQL Server 2025 (17.x) 预览版
- 由 Azure Arc 启用的 SQL Server
- 启用
sp_configure 'allow server scoped db credentials'
更新注册表
警告
错误编辑注册表会严重损坏您的系统。 更改注册表之前,建议备份计算机中所有重要的数据。
更新注册表子项 \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQLServer\FederatedAuthentication。 为数据存储类型添加以下条目。
| 项 | 价值 |
|---|---|
AADDataLakeEndPoint |
datalake.azure.net |
AADAzureStorageEndPoint |
storage.azure.com |
这些密钥是在 Azure Arc 启用 SQL Server 的托管标识(预览版)中所述所需的注册表项之外添加的。
创建数据库范围凭据
为托管标识添加数据库作用域凭据。
允许服务器范围内的数据库凭证。 运行以下命令。
EXECUTE sp_configure 'allow server scoped db credentials',1; GO RECONFIGURE;创建数据库范围的凭据。 该示例使用名称
managed_id。CREATE DATABASE SCOPED CREDENTIAL [managed_id] WITH IDENTITY = 'Managed Identity';
创建外部数据源
创建外部数据源。
| 外部数据源 | 连接器位置前缀 | 位置路径 | 产品/服务支持的地点 | Authentication |
|---|---|---|---|---|
| Azure 存储帐户 (V2) | abs |
abs://<container_name>@<storage_account_name>.blob.core.windows.net/或 abs://<storage_account_name>.blob.core.windows.net/<container_name> |
- SQL Server 2022 (16.x):支持的分层命名空间 - 由 Azure Arc 启用的 SQL Server 2025 (17.x) 预览版 |
共享访问签名 (SAS) 或 托管身份 |
| Azure Data Lake Storage | adls |
adls://<container_name>@<storage_account_name>.dfs.core.windows.net/或 adls://<storage_account_name>.dfs.core.windows.net/<container_name> |
- SQL Server 2022 (16.x) - 由 Azure Arc 启用的 SQL Server 2025 (17.x) 预览版 |
共享访问签名 (SAS) 或 托管身份 |
在 Azure Blob 存储中查询 Parquet 文件
SQL Server 2025 (17.x)预览版支持通过 Azure Arc 托管标识。有关说明,请查看 Azure Arc 启用的 SQL Server 的托管标识(预览版)。
以下示例在 Azure Blob 存储中查询 Parquet 文件
EXECUTE sp_configure 'allow server scoped db credentials', 1;
RECONFIGURE;
GO
CREATE DATABASE SCOPED CREDENTIAL [managed_id]
WITH IDENTITY = 'Managed Identity';
CREATE EXTERNAL DATA SOURCE [my_external_data_source]
WITH (
LOCATION = 'abs://<container>@<storage_account_name>.blob.core.windows.net/',
CREDENTIAL = managed_id
);
错误和解决方案
Azure Arc 启用的 SQL Server 2025 (17.x) 预览版无法使用托管标识进行身份验证。
若要使用托管标识,Azure Arc 必须启用 SQL Server 2025 (17.x) 预览版。有关如何通过 Azure Arc 启用的说明,请查看 Azure Arc 启用的 SQL Server 的托管标识(预览版)。
启用 sp_configure 'allow server scoped db credentials'。
如果存在以下任一情况,PolyBase 查询将失败:
- 未为 Azure Arc 正确配置 SQL Server 实例
- 缺少注册表项
-
allow server scoped db credentials已禁用
尝试访问 Azure Blob 存储或 Azure Data Lake 时,查询将返回以下错误之一:
Msg 16562, Level 16, State 1, Line 79
External table <name> is not accessible because location does not exist or it is used by another process.
或
Msg 16562, Level 16, State 1, Line 79
External table <name> is not accessible because location does not exist or it is used by another process.