You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Databricks Statement Execution API:如何解决存储请求未授权错误

问题:调用Azure Databricks Statement Execution API查询Delta Lake时遇到存储授权错误

我正尝试通过C# .NET应用调用Azure Databricks Statement Execution API查询Delta Lake,应用代码如下:

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace DatabricksApiApp
{
    class Program
    {
        static readonly HttpClient client = new HttpClient();

        static async Task Main(string[] args)
        {
            try
            {
                // Set up the endpoint and the access token
                string baseUrl = "https://adb-7765225718529619.19.azuredatabricks.net/api/2.0/sql/statements";
                string accessToken = "dapbmi7a544bbc6d0e05a1ec650b85570b70";
                string warehouseId = "ff9d6456ff77bcs84";

                // Prepare the HTTP request
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, baseUrl)
                {
                    Content = new StringContent(
                        "{\"statement\":\"SELECT * FROM maindev.default.product_1\", \"warehouse_id\":\"ff9d6456ff77bcs84\", \"timeout_seconds\":600}",
                        Encoding.UTF8,
                        "application/json"
                    )
                };
                request.Headers.Add("Authorization", $"Bearer {accessToken}");

                // Send the request
                HttpResponseMessage response = await client.SendAsync(request);

                // Check the response
                if (response.IsSuccessStatusCode)
                {
                    string responseBody = await response.Content.ReadAsStringAsync();
                    Console.WriteLine("Data retrieved successfully!");
                    Console.WriteLine(responseBody);
                }
                else
                {
                    Console.WriteLine($"Failed to retrieve data. Status code: {response.StatusCode}");
                    string responseBody = await response.Content.ReadAsStringAsync();
                    Console.WriteLine($"Response Body: {responseBody}");
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }
        }
    }
}

请求已成功到达Databricks,但返回如下错误:

This Azure storage request is not authorized. The storage account's 'Firewalls and virtual networks' settings may be blocking access to storage services. Please verify your Azure storage credentials or firewall exception settings.

错误未指明需要授权的具体存储资源,请问应如何解决此问题?


解决方法

  • 定位关联的存储账户

    1. 登录Azure Databricks工作区,在Data Explorer中找到maindev.default.product_1表,右键查看属性,从Location字段获取存储路径(格式通常为abfss://容器名@存储账户名.dfs.core.windows.net/路径),提取其中的存储账户名。
    2. 也可通过Databricks CLI执行命令:databricks tables describe maindev.default.product_1,在输出中找到存储路径信息。
  • 检查存储账户的防火墙与网络设置

    1. 登录Azure门户,找到目标存储账户,进入防火墙和虚拟网络配置页。
    2. 若设置为“允许从选定的网络访问”,需满足以下任一条件:
      • 将运行C#应用的主机IP添加到存储账户的允许IP列表;
      • 若应用部署在Azure虚拟网络内,将该VNet添加到允许列表,并启用“允许受信任的Microsoft服务访问此存储账户”选项(Databricks属于受信任服务,可通过此权限访问存储);
    3. 测试阶段可临时切换为“允许从所有网络访问”,验证问题是否解决,确认后再调整为严格权限。
  • 验证存储访问凭据有效性

    1. 若使用Unity Catalog管理外部位置:进入Unity Catalog的外部位置设置,确认关联的凭据(Service Principal密钥/SAS令牌)未过期,且拥有存储容器的读取权限;
    2. 若使用传统挂载点:检查挂载时配置的凭据是否有效,可重新执行挂载命令测试访问。
  • 确认Databricks仓库的网络配置

    1. 查看目标Databricks SQL仓库(ID:ff9d6456ff77bcs84)的网络模式:
      • 若为“无隔离”模式,需确保存储账户允许公共网络访问;
      • 若为“VNet注入”模式,需确保存储账户的允许网络列表包含仓库所在VNet,或启用了受信任服务访问。

内容的提问来源于stack exchange,提问作者Eugene Goldberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 03:12:43