1

How to put AAD session value instead on password and user name in the code shown here:

    import com.microsoft.azure.sqldb.spark.config.Config
    import com.microsoft.azure.sqldb.spark.connect._

    val config = Config(Map(
      "url"            -> "kkk-server.database.windows.net:1433",
      "databaseName"   -> "MyDatabase",
      "dbTable"        -> "dbo.Clients",
      "user"           -> "AD-account",
      "password"       -> "xxxxxxxx",
      "connectTimeout" -> "5", //seconds
      "queryTimeout"   -> "5"  //seconds
    ))

    val collection = spark.read.sqlDB(config)
    collection.show()
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gaurav Gangwar
  • 467
  • 3
  • 11
  • 24

2 Answers2

1

You can use the Spark connector for SQL Server and Azure SQL Database in Azure Databricks.

The Spark connector for SQL Server and Azure SQL Database also supports Azure Active Directory (AAD) authentication. It allows you to securely connect to your Azure SQL databases from Azure Databricks using your AAD account. It provides interfaces that are similar to the built-in JDBC connector.

Here's the example:

import com.microsoft.azure.sqldb.spark.config.Config
import com.microsoft.azure.sqldb.spark.connect._

val config = Config(Map(
  "url"            -> "mysqlserver.database.windows.net",
  "databaseName"   -> "MyDatabase",
  "user"           -> "username ",
  "password"       -> "*********",
  "authentication" -> "ActiveDirectoryPassword",
  "encrypt"        -> "true"
))

val collection = sqlContext.read.SqlDB(config)
collection.show()

For more details, please see: Connect Spark to Azure SQL Database using AAD authentication

Hope this helps.

Leon Yue
  • 15,693
  • 1
  • 11
  • 23
  • But here we need to expose the password for my SSO login which is not feasible. – Gaurav Gangwar Jul 30 '19 at 05:40
  • Maybe you can reference the answer of this blog: https://stackoverflow.com/questions/52790776/getting-error-while-databricks-connection-to-azure-sql-db-with-activedirectorypa – Leon Yue Jul 30 '19 at 06:02
0

Using Azure Active Directory (AAD) authentication to connect to Azure SQL Database on Azure Databricks is not possible at this time. You should use SQL authentication.

If you try AAD authentication on Azure Databricks you may get error "This driver is not configured for integrated authentication" or similar error message.

Although it is possible to use AAD in Azure Data Lake.

Alberto Morillo
  • 13,893
  • 2
  • 24
  • 30