none
Azure data factory v2 custom activities. Get a connection string from a linkedService with Azure Key Vault

    Question

  • I a custom activity with a linkedService in ReferenceObjects property. I get the linkedService from linkedService.json but its connection string is from a KeyVault not from string value. How can i get the connectionString to open a SqlConnection from the custom activitiy.

    Example:

    My pipeline:

    {
        "name": "myPipeline",
        "properties": {
            "activities": [
                {
                    "name": "myCustomActivity",
                    "type": "Custom",
                    "policy": {
                        "timeout": "02:00:00",
                        "retry": 3,
                        "retryIntervalInSeconds": 30,
                        "secureOutput": false,
                        "secureInput": false
                    },
                    "typeProperties": {
                        "command": "test.exe",
                        "resourceLinkedService": {
                            "referenceName": "blobLS",
                            "type": "LinkedServiceReference"
                        },
                        "folderPath": "testContainer/Test",
                        "referenceObjects": {
                            "linkedServices": [
                                {
                                    "referenceName": "AzureSqlLinkedService",
                                    "type": "LinkedServiceReference"
                                }
                            ]
                        }
                    },
                    "linkedServiceName": {
                        "referenceName": "BatchLS",
                        "type": "LinkedServiceReference"
                    }
                }
            ]
        }
    }

    My reference linkedService:

    {
        "name": "AzureSqlLinkedService",
        "properties": {
            "type": "AzureSqlDatabase",
            "typeProperties": {
                "connectionString": {
                    "type": "AzureKeyVaultSecret",
                    "store": {
                        "referenceName": "keyVaultLinkedService",
                        "type": "LinkedServiceReference"
                    },
                    "secretName": "mySecretName"
                }
            }
        }
    }

    and my custom activity:

    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System;
    using System.Linq;
    using System.IO;
    using System.Data.SqlClient;

    namespace MyCustomActivities
    {
        class Program
        {
            static void Main(string[] args)
            {
                dynamic linkedServices = JsonConvert.DeserializeObject(File.ReadAllText("linkedServices.json"));
                string connectionString = ((dynamic)(((JArray)linkedServices).Where(
                                linkedService =>
                                ((dynamic)linkedService).name.ToString().Equals("odsStagingLS"))).First()).properties.typeProperties.connectionString;
                //Here i have the json code but in value it isn't the connectionString because it use Key Vault.
                //How i get the conectionString to to the follow
                SqlConnection connection = new SqlConnection(connectionString);
            }
        }
    }


    • Edited by jyeros Thursday, November 1, 2018 10:39 PM
    Thursday, November 1, 2018 10:39 PM

All replies