【发布时间】:2019-08-12 05:49:46
【问题描述】:
有人可以帮助我使用 azure 数据工厂实现与数据库的动态连接吗?
【问题讨论】:
-
请添加更多详细信息,说明您正在尝试完成的工作、您尝试过的内容以及您正在尝试做的一些示例。
标签: azure azure-sql-database azure-cosmosdb azure-data-factory azure-databricks
有人可以帮助我使用 azure 数据工厂实现与数据库的动态连接吗?
【问题讨论】:
标签: azure azure-sql-database azure-cosmosdb azure-data-factory azure-databricks
使用 azure 数据工厂实现与数据库的动态连接
基于此文档Parameterize linked services in Azure Data Factory,到目前为止,您现在可以参数化链接服务并在运行时传递动态值。
它支持 Cosmos DB:
顺便说一句,MS 建议不要参数化密码或机密。将所有连接字符串存储在 Azure Key Vault 中,并参数化 Secret Name。关于详细信息,请参阅此link。
更新答案:
db name 当然可以参数化。
您可以在创建 cosmos db 链接服务时配置动态数据库名称。
单击动态内容并创建新参数。
更新答案 2:
请参考这个sdk function和我的工作代码如下:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.datafactory import DataFactoryManagementClient
from azure.mgmt.datafactory.models import *
# Azure subscription ID
subscription_id = '***'
# This program creates this resource group. If it's an existing resource group, comment out the code that creates the resource group
rg_name = '***'
# The data factory name. It must be globally unique.
df_name = '***'
# Specify your Active Directory client ID, client secret, and tenant ID
credentials = ServicePrincipalCredentials(client_id='***',
secret='***',
tenant='***')
resource_client = ResourceManagementClient(credentials, subscription_id)
adf_client = DataFactoryManagementClient(credentials, subscription_id)
resource_client.resource_groups.get(rg_name)
# Create a data factory
df_resource = Factory(location='eastus')
df = adf_client.factories.get(rg_name, df_name, df_resource)
print(df)
ls_name = 'testlink1'
dbName = "<your db name>"
connection_string = 'AccountEndpoint=https://***.documents.azure.com:443/;AccountKey=***;Database='+dbName+';';
ls_cosmos_db = CosmosDbLinkedService(connection_string=connection_string)
ls = adf_client.linked_services.create_or_update(rg_name, df_name, ls_name, ls_cosmos_db)
print(ls)
更多细节,可以参考官方create linked service example code和python sdk for ADF management。
【讨论】: