如何使用用户分配托管标识实现Azure Databricks与Azure Synapse的正确连接
使用用户分配托管标识从Databricks连接Azure Synapse的正确配置
问题根源
你的JDBC URL格式错误:User Id与Authentication参数之间缺少分号分隔,且使用用户分配托管标识(UMSI)时未正确指定标识ID,导致连接器无法识别有效凭证。
正确配置代码
以下是使用用户分配托管标识连接Synapse专用池的正确PySpark代码,包含两种可行格式:
格式一:通过userAssignedIdentityId参数指定UMSI
df.write \ .format("com.databricks.spark.sqldw") \ .option("url", "jdbc:sqlserver://<synapse server name>.sql.azuresynapse.net;database=<dedicated pool name>;Authentication=ActiveDirectoryMSI;Use Encryption for Data=true;") \ .option("useAzureMSI", "true") \ .option("userAssignedIdentityId", "<umsi_synapse_user的Client ID或Object ID>") \ .option("dbtable", "table_name") \ .option("truncate", "false") \ .option("tempDir", "abfss://<azure_storage_name>@<container_name>.dfs.core.windows.net/tempDir") \ .mode("overwrite") \ .save()
格式二:在JDBC URL中指定UMSI的ID
df.write \ .format("com.databricks.spark.sqldw") \ .option("url", "jdbc:sqlserver://<synapse server name>.sql.azuresynapse.net;database=<dedicated pool name>;User Id=<umsi_synapse_user的Client ID>;Authentication=ActiveDirectoryMSI;Use Encryption for Data=true;") \ .option("useAzureMSI", "true") \ .option("dbtable", "table_name") \ .option("truncate", "false") \ .option("tempDir", "abfss://<azure_storage_name>@<container_name>.dfs.core.windows.net/tempDir") \ .mode("overwrite") \ .save()
关键修改说明
- JDBC URL规范:确保参数间用分号分隔,
Authentication=ActiveDirectoryMSI明确指定MSI认证方式 - 用户分配标识指定:必须通过
userAssignedIdentityId参数或URL中的User Id指定UMSI的Client ID/Object ID(从Azure门户的托管标识资源详情中获取) - 权限验证:确认
umsi_synapse_user对ADLS Gen2临时目录拥有存储Blob数据参与者权限,确保临时文件读写正常
内容的提问来源于stack exchange,提问作者user1651818
相关产品推荐
相关产品推荐

