使用azure datafactory SSIS将zip文件上载到blob存储的脚本任务

时间:2018-05-07 07:31:18

标签: azure ssis azure-sql-database azure-storage-blobs azure-data-factory

我有一个天蓝色的数据工厂项目。我需要从Azure SQL数据库中查询一些数据,然后加载到xml中,压缩它并上传到blob sotrage。我不想在文件系统上写任何东西(因为我认为Azure数据库没有任何存储空间)所以我使用的是Memorystream。

此脚本任务正在​​处理我的本地SSIS数据库,但不适用于Azure Datafactory:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Collections;
using System.Linq;
using System.Data.OleDb;
using System.IO;

using System.IO.Compression;
using System.Data.SqlClient;
using Microsoft.Azure;

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;


public void Main()
    {

        CloudStorageAccount storageAccount = null;
        CloudBlobContainer cloudBlobContainer = null;


        try
        {

            DataSet ds = new DataSet("FullList");
            OleDbDataAdapter oleDa = new OleDbDataAdapter();

            DataTable dt = new DataTable("CustomerTable");
            oleDa.Fill(dt, Dts.Variables["User::CustomerSelect"].Value);
            ds.Tables.Add(dt);

            DataTable dt_product = new DataTable("ProductTable");
            oleDa.Fill(dt_product, Dts.Variables["User::ProductSelect"].Value);
            ds.Tables.Add(dt_product);



            DataRelation relation = ds.Relations.Add("relation", ds.Tables["CustomerTable"].Columns["id"], ds.Tables["ProductTable"].Columns["id"]);
            relation.Nested = true;


            string connstring = Dts.Connections["testolgdev"].AcquireConnection(Dts.Transaction).ToString();
            if (CloudStorageAccount.TryParse(connstring, out storageAccount))
            {
                try
                {
                    CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();


                    cloudBlobContainer = cloudBlobClient.GetContainerReference("flat");

                    string fileName = "xml" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".zip";
                    var blob = cloudBlobContainer.GetBlockBlobReference(fileName);
                    using (var stream = new ZipArchive(blob.OpenWrite(), ZipArchiveMode.Create))
                    {
                        var entry = stream.CreateEntry("test_dataset_fullresult_onlymem.xml");
                        using (var es = entry.Open())
                        {
                            ds.WriteXml(es);
                        }


                    }



                }
                catch (StorageException ex)
                {
                    Console.WriteLine("Error returned from the service: {0}", ex.Message);
                }
            }
            else
            {
                Console.WriteLine("Wrong connection string");
            }



        }
        catch (TargetInvocationException e)
        {

            throw;
        }

  Dts.TaskResult = (int)ScriptResults.Success;
}

当我部署并执行它时,这是Azure Datafactory SSIS错误:

脚本任务1:错误:无法加载文件或程序集' Microsoft.WindowsAzure.Storage,Version = 4.3.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)

有可能解决这个问题吗?我可以将缺少的dll添加到Azure Datafactory吗?

1 个答案:

答案 0 :(得分:2)

通过本指南,我可以将缺少的dll添加到Azure-SSIS IR:
https://docs.microsoft.com/en-us/azure/data-factory/how-to-configure-azure-ssis-ir-custom-setup.

感谢 Sandy Winarko(MSFT)的答案!