Forum Discussion

cw88's avatar
cw88
Icon for Helper IV rankHelper IV
1 year ago
Solved

Parameterized connections in Data pipelines

Hello,
Has anyone already used the new feature “Parameterized connections in Data pipelines” from the march summary? Unfortunately, apart from the small section in the blog, I can't find anything about it, e.g. an example with connection, parameters, ...

  • cw88's avatar
    cw88
    1 year ago

    Hello v-saisrao-msft ,

    sorry, but your answer doesn't help me. 

    I don't know if it is working or not, and it is no documentation how it works... 

     

    For all others who want to use the feature: For my case i works, when i use the connection id as parameter in "connection". To get the connectionid, I stored the fixed connection and found the id in the json.

20 Replies

  • Vaughan_Brant's avatar
    Vaughan_Brant
    Frequent Visitor

    I know this is an old thread but thought it might be worth posting this.

    To make things a little more human friendly you can have a variables library containing the connection_name. 

    Pass the connection name from the Variable Library as a parameter to a lightweight Python notebook that resolves the corresponding Fabric connection ID.

    A copy data activity can use the notebook exit value as the dynamic connection. So in a notebook you'd have a parameter cell, somthing like this:

    connection_name = ''

    followed by a code cell, something like this:

    import requests
    from urllib.parse import quote
    
    connection_name = connection_name.strip()
    
    if not connection_name:
        raise ValueError("connection_name must be provided")
    
    token = notebookutils.credentials.getToken(
        "https://api.fabric.microsoft.com"
    )
    
    headers = {
        "Authorization": f"Bearer {token}"
    }
    
    base_url = "https://api.fabric.microsoft.com/v1/connections"
    url = base_url
    matches = []
    
    while url:
        response = requests.get(url, headers=headers, timeout=30)
        response.raise_for_status()
    
        payload = response.json()
    
        matches.extend(
            connection
            for connection in payload.get("value", [])
            if connection.get("displayName", "").casefold()
            == connection_name.casefold()
        )
    
        continuation_token = payload.get("continuationToken")
    
        url = (
            f"{base_url}?continuationToken="
            f"{quote(continuation_token, safe='')}"
            if continuation_token
            else None
        )
    
    if len(matches) == 0:
        raise ValueError(
            f"Fabric connection not found: '{connection_name}'"
        )
    
    if len(matches) > 1:
        raise ValueError(
            f"Fabric connection name is not unique: '{connection_name}'"
        )
    
    connection = matches[0]
    
    print(f"Connection name: {connection['displayName']}")
    print(f"Connection ID:   {connection['id']}")
    
    notebookutils.notebook.exit(connection["id"])

    Rather than storing environment-specific connection GUIDs in parameters or a Variable Library, store the human-readable connection name. At runtime, resolve that name against the Fabric Connections API and pass the resulting connection ID to the Copy activity.

    That avoids hard-coding a connection ID which could change if the connection is deleted and recreated, while still allowing DEV/TEST/PROD to use different connections through environment-specific Variable Library values.

    A Variable Library expression containing the correct connection GUID works when the pipeline runs, but the Copy activity designer may fail to refresh metadata or preview data. Entering the same GUID literally allows the designer to refresh and preview.

  • jochenj's avatar
    jochenj
    Icon for Advocate III rankAdvocate III

    we also on the way to leverage that new feature...following findings (without documentation):

    Creation/Development Phase
    1. Yes, you need to specify the ID, you can get the ID from GatewayMgt>Connections, of the connection as dynamic content. 

    2. When you create a dynamic connection, dedendant on "connection type", additonal fields need to be provided:
             2.1 Type "Fabric SQL Database" = WorkspaceID and SQLDatabaseID needed
             2.2 Type "SQL Server" = DatabaseName?

    Deployment Phase
    Of course making connections dynamic is only one half of the story, the other half is to deploy this pipelines to other workspaces and run them with other parameter values...
    Findings:
    1. So if you have connections which need "WorkspaceID" you can leverage the system.workspaceID variable to make the parameter value dynamic across workspaces
    2. The ConnectionID seems, at least for Fabric-conncetion-types like WH,LH,Database, the same accross workspaces.
    3. For other connection-types you need a way to centrally manage different ConnectionIDs per Workspace

    ISSUE:
    The "THREAT AS NULL" settings are not deployed with Fabric Deployment Pipelines for our scenario 😞
    Repro Steps:
    1. Create a DEV and PROD Workspace
    2. in the DEV workspace create a pipeline1 with a "Lookup" Activity to call a SQL Server Stored Procedure. Make the Connection for the DB with the proc dynamic.
    - The SQL Proc needs to have multiple input parameters which are optional, so they need to be flagged in pipeline.LookupActivity.settings.parameter as "TREAT AS NULL"
    - If you now deploy pipeline1 from DEV to PROD Workspace with Fabric Pipeline the "THREAT AS NULL" info get lost. If you open pipeline Editor>View>EDIT JSON Code we can see the difference causing the issue:


    DEV Pipeline:

     




    PROD Pipeline:


    The current workaround is to update the pipelines in PROD after deployment manually , but this is not how it shoud be.... can someone from microsoft qualify that as an bug?

     

  • arpost's avatar
    arpost
    Icon for Post Prodigy rankPost Prodigy

    I have the same question. Not a lot of detail/documentation on how exactly to configure this. I am wanting to know how to use connections with Fabric SQL DBs, Fabric DWs, Notebooks, etc.

  • v-saisrao-msft's avatar
    v-saisrao-msft
    Icon for Community Support rankCommunity Support

    Hi cw88,
    Thank you for reaching out to the Microsoft Fabric Forum Community. 

    Just to better understand your scenario and possibly help further: 

    • Could you please share which type of connection or data source you're trying to parameterize? 
    • Are you currently working with Microsoft Fabric Data Pipelines or Azure Data Factory? 
    • Also, may I ask what your intended use case is for parameterizing the connection? 

    Thank you. 

    • cw88's avatar
      cw88
      Icon for Helper IV rankHelper IV

      v-saisrao-msft . 

      I want to parametrize a connection to an onprem sql server, working with Fabric Data Pipeline. Use case: general parameterization of connections to be more flexible in case of changes.

       

      First question: Do i have to enter the connectionid or the name? If it is the ID: Where do I get the ID of a connection?

      - 

      • v-saisrao-msft's avatar
        v-saisrao-msft
        Icon for Community Support rankCommunity Support

        Hi cw88,
        Thank you for reaching out to the Microsoft Fabric Forum Community.

        Parameterized connections in Microsoft Fabric Data Pipelines offer a way to pipeline flexibility, especially across different environments or datasets. When working within the Fabric UI, you should reference the connection name, not the connection ID. The connection name can be found under Settings > Manage connections and gateways, and it must match exactly. 
        For on-premises SQL Server connections, ensure the connection is configured through an On-premises Data Gateway using Basic authentication, which is currently required. To implement parameterization, you can define pipeline parameters such as Database Name and reference them using dynamic expressions like @pipeline().parameters.DatabaseName within the source settings of your Copy Data activity. This enables scenarios such as dynamically switching between databases without modifying the pipeline structure. 

        If you need to switch entire connections, you can also parameterize the connection name using a parameter like Connection Name and reference it as @pipeline().parameters.ConnectionName. 

         

        If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

         

        Thank you.