Execute stored procedure from Azure datafactory

后端 未结 2 743
被撕碎了的回忆
被撕碎了的回忆 2021-01-16 00:17

I am trying to execute a stored procedure in an Azure SQL database from an Azure DataFactory V2. The procedure will do some upsert into different tables with data from a fla

2条回答
  •  Happy的楠姐
    2021-01-16 00:19

    Following the advice of @Martin we managed to make the execution work. Below are what we did:

    1. Create dummy table in SQL:

      CREATE TABLE [dbo].[dummyTable]( [col1] [NVARCHAR](100) NULL)
      
    2. Create a stored procedure:

      CREATE PROCEDURE [dbo].[sp_testHarmonize]
           @param1 NVARCHAR(200)
      AS
      BEGIN
          INSERT INTO storedProcedureExecutions
          VALUES (@param1, GETDATE());
      END
      
    3. Dataset for the stored procedure:

      {
          "type": "datasets",
          "name": "[parameters('dummySQLTableDataSet')]",
          "dependsOn": ["[parameters('dataFactoryName')]",
          "[parameters('datalakeLinkedServiceName')]"],
          "apiVersion": "[variables('apiVersion')]",
          "properties": {
                  "type": "AzureSqlTable",
                  "linkedServiceName": {
                      "referenceName": "[parameters('databaseLinkedServiceName')]",
                      "type": "LinkedServiceReference"
                  },
          "typeProperties": {
                  "tableName": "dummyTable"
          }
      }
      
    4. Pipeline activity:

      {
          "name": "ExecuteHarmonizationProcedure",
          "dependsOn": [{
              "activity": "CopyCSV2SQL",
              "dependencyConditions": ["Succeeded"]
          }],
          "description": "Executes the procedure that Harmonizes the Data",
          "type": "Copy",
          "inputs": [{
              "referenceName": "[parameters('dummySQLTableDataSet')]",
              "type": "DatasetReference"
          }],
          "outputs": [{
              "referenceName": "[parameters('dummySQLTableDataSet')]",
              "type": "DatasetReference"
          }],
          "typeProperties": {
              "source": {
                  "type": "SqlSource",
                  "sqlReaderQuery": "@Pipeline().parameters.SQLCommand"
              },
              "sink": {
                  "type": "SqlSink"
              }
          }
      }
      
    5. Run the pipeline with the following parameter for the SQL command:

      $"EXEC sp_testHarmonize 'call from ADF at {DateTime.Now}'; select top 1 * from dummyTable;"
      

    This made it worked, but it looks more as a work around than a direct solution, considering that it is inserted a row on a dummy table. If there isn't any more direct solution, this is the most easy approach.

提交回复
热议问题