[英]How to connect to Azure SQL Server in databricks using active directory authentication
In the below code I am using SQL Server user id and password to connect to my db. 在下面的代码中,我使用SQL Server用户ID和密码连接到我的数据库。
But I get an error while connecting with active directory. 但是在连接活动目录时出错。
Please Suggest some solution to connect Azure SQL Server DB in Azure Databricks using Active Directory authentication. 请建议使用Active Directory身份验证在Azure Databricks中连接Azure SQL Server数据库的一些解决方案。
As of now, I am able to connect with a JDBC connection: 截至目前,我能够连接JDBC连接:
sql_url="jdbc:sqlserver://kkk-server.database.windows.net:1433;database=database;user=UserName;password=Password"
According the Azure databricks document Connecting to Microsoft SQL Server and Azure SQL Database with the Spark Connector : 根据Azure数据库文档使用Spark Connector连接到Microsoft SQL Server和Azure SQL数据库 :
The Spark connector for SQL Server and Azure SQL Database also supports Azure Active Directory (AAD) authentication. SQL Server和Azure SQL数据库的Spark连接器还支持Azure Active Directory(AAD)身份验证。 It allows you to securely connect to your Azure SQL databases from Azure Databricks using your AAD account.
它允许您使用AAD帐户从Azure Databricks安全地连接到Azure SQL数据库。
Example: Read from Azure SQL Database or SQL Server : 示例: 从Azure SQL数据库或SQL Server中读取 :
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()
Replace the user with your AD account name. 用您的AD帐户名替换用户。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.