簡體   English   中英

Databricks JDBC 連接有效,但查詢失敗

[英]Databricks JDBC Connections works but query fails

我正在嘗試通過 Azure Databricks 建立與 SQL 服務器數據庫的連接。 雖然有許多問題試圖緩解這里的問題,但我還沒有找到適合我的解決方案。

我能夠連接,至少看起來是因為 DataFrame (spark) object 從我的數據庫表中讀取了確切的模式,但在嘗試查看數據( display(df)df.show() )時它會引發連接錯誤。

這是我的連接方式:

jdbcUrl = "jdbc:sqlserver://{}:{};database={}".format(jdbcHostname, jdbcPort, jdbcDatabase)

connectionProperties = {
  'user': jdbcUsername,
  'password': jdbcPassword,
  "driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
}

pushdown_query = "(select * from persons where personid = 3040) Person"
df = spark.read.jdbc(url=jdbcUrl, table=pushdown_query, properties=connectionProperties)
display(df)

我可以看到 object df並正確識別表中的所有 47 個字段(見下圖),但display(df)引發以下錯誤:

SQLServerException: The TCP/IP connection to the host hornets-sql.westus.cloudapp.azure.com, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

在此處輸入圖像描述

默認情況下,SQL 服務器啟用了防火牆,不允許從任意 IP 訪問。 在您的情況下,您可能在防火牆中允許驅動程序節點 - 這就是您獲得表模式的原因,但讀取本身發生在防火牆上可能未啟用的工作節點上,並且讀取失敗。

您可以嘗試通過以下方式解決:

  1. SQL服務器防火牆添加所有worker節點的公網IP
  2. 或通過將Azure SQL 的專用鏈接/端點配置到您的 VNet 中
  3. 或為 Azure 服務使用服務端點

最后兩項在 Databrick 的博客文章中得到了很好的介紹。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM