简体   繁体   English

无法从 azure 数据块连接到 sql server 托管实例

[英]Can't connect to sql server managed instance from azure databricks

I am trying to connect to an Azure Sql managed instance from databricks.我正在尝试从数据块连接到 Azure Sql 托管实例。 I am using Scala to connect to it.我正在使用 Scala 连接到它。 The code I have copied from the Microsoft web site我从微软网站复制的代码

My actual scala code : (I have changed the credentials and IP. But I have made sure they are correct as I have copied them from the connection strings in the sql server managed instance options)我的实际 scala 代码:(我已经更改了凭据和 IP。但是我确保它们是正确的,因为我已经从 sql server 托管实例选项中的连接字符串中复制了它们)

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
val jdbcHostname = "dev-migdb.nf53e3653n43.database.windows.net"
val jdbcPort = 1433
val jdbcDatabase = "MYDB"

// Create the JDBC URL without passing in the user and password parameters.
val jdbcUrl = s"jdbc:sqlserver://${jdbcHostname}:${jdbcPort};database=${jdbcDatabase};loginTimeout=90"

// Create a Properties() object to hold the parameters.
import java.util.Properties
val connectionProperties = new Properties()

connectionProperties.put("user", "db-devmigmgd")
connectionProperties.put("password", "pwd##321232123")

val driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionProperties.setProperty("Driver", driverClass)

val employees_table = spark.read.jdbc(jdbcUrl, "employees", connectionProperties)
0

Error :错误 :

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host dev-migdb.nf53e3653n43.database.windows.net, port 1433 has failed. Error: "Connection timed out: no further information. 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.".
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:227)
    at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:284)
    at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2435)
    at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:635)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2010)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1687)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1528)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:866)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:569)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$1.apply(JdbcUtils.scala:63)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$1.apply(JdbcUtils.scala:54)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:56)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation$.getSchema(JDBCRelation.scala:210)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:35)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:336)
    at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:286)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:274)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:198)
    at org.apache.spark.sql.DataFrameReader.jdbc(DataFrameReader.scala:301)
    at linee84eb162c20345fc84ad591cfefe930f29.$read$$iw$$iw$$iw$$iw$$iw$$iw.<init>(command-999597493877319:49)
    at linee84eb162c20345fc84ad591cfefe930f29.$read$$iw$$iw$$iw$$iw$$iw.<init>(command-999597493877319:104)

On the other hand :另一方面 :

  1. I am able to connect to the same managed instance from the VM that is there on the same Azure subscription (using SSMS)我能够从同一 Azure 订阅上的 VM 连接到同一托管实例(使用 SSMS)
  2. My custom application that is written in .Net and hosted on that VM is also able to connect to the same instance我用 .Net 编写并托管在该 VM 上的自定义应用程序也能够连接到同一个实例

Also, I am unable to connect to the same instance from scala code that I am executing using spark shell on the above VM.此外,我无法从我在上述 VM 上使用 spark shell 执行的 Scala 代码连接到同一个实例。 BUT the errors that I am getting are different.但是我得到的错误是不同的。 Please find errors below.请在下面查找错误。

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'db-devmigmgd@dev-migdb'.
  at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
  at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
  at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2529)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
  at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4874)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
  at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
  at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$1.apply(JdbcUtils.scala:63)
  at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$1.apply(JdbcUtils.scala:54)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:56)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation$.getSchema(JDBCRelation.scala:210)
  at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:35)
  at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:318)
  at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:167)
  at org.apache.spark.sql.DataFrameReader.jdbc(DataFrameReader.scala:238)
  ... 76 elided

Thanks @simon_dmorias,谢谢@simon_dmorias,

As per your comments and discussions with the Microsoft team, resources on different VNET was the real problem.根据您与 Microsoft 团队的评论和讨论,不同 VNET 上的资源才是真正的问题。

So as a best practice, always create resources in the same VNETs.因此,作为最佳实践,始终在相同的 VNET 中创建资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Azure Databricks Notebook 访问 SQL 服务器 - Accessing SQL Server from the Azure Databricks Notebook Slick无法连接到SQL Server数据库 - Slick can't connect to SQL Server Database 使用 Azure Databricks 从 Azure Databricks 从 Azure Sql 表中删除行 - Delete rows from Azure Sql table using Azure Databricks with Scala 在 Azure Databricks 中使用 Python 将 DF 写入 SQL Server - Working with Python in Azure Databricks to Write DF to SQL Server 从 Azure databricks notebook 连接到 HDFS 位置获取文件数量和大小 - Connect to HDFS location from Azure databricks notebook to get the file number and size 如何从 Azure Databricks Notebook 直接读取 Azure Blob 存储文件 - How can I read an Azure Blob Storage file direclty from an Azure Databricks Notebook 使用 azure 数据块 scala 将数据从 blob 存储加载到 sql 数据仓库 - Data load from blob storage to sql data warehouse using azure databricks scala 直接使用来自 Databricks 的原始 SQL 查询存储在 Azure Data Lake 中的 avro 数据文件 - Querying avro data files stored in Azure Data Lake directly with raw SQL from Databricks 从 Databricks 写入 Azure cosmos DB 的问题 - Issue with write from Databricks to Azure cosmos DB 如何在 Scala 中使用服务主体连接到 Azure SQL Server - How to connect to an Azure SQL Server using service principal in Scala
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM