简体   繁体   English

使用SSIS脚本组件读取Azure Data Lake Store文件

[英]Azure Data Lake Store File read using SSIS Script Component

Appreciate your suggestions. 感谢您的建议。
My Requirement is, Read json file from ADLS using SSIS and load into SQL table 我的要求是,使用SSIS从ADLS读取json文件并加载到SQL表中

Implementation: I have implemented the code to read json file content in .Net Console app. 实现:我已经实现了在.Net Console应用程序中读取json文件内容的代码。 This is working fine in Console app. 这在控制台应用程序中工作正常。 I copied the same code in SSIS Script component, but it throws "The type initializer for 'Microsoft.Azure.DataLake.Store.AdlsClient' threw an exception" exception in AdlsClient.CreateClient. 我在SSIS脚本组件中复制了相同的代码,但是在AdlsClient.CreateClient中引发了“'Microsoft.Azure.DataLake.Store.AdlsClient'的类型初始化程序引发异常”异常

using Microsoft.Rest;
using Microsoft.Rest.Azure.Authentication;
using Microsoft.Azure.Management.DataLake.Store;
using Microsoft.Azure.DataLake.Store;
using Microsoft.Azure.DataLake.Store.AclTools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

JObject results = new JObject();
        string applicationId = "<appid>;
        string secretKey = <secretekey>;
        string tenantId = <tenantid>;
        string adlsAccountName = "<ADLSNAME>.azuredatalakestore.net";
        ServiceClientCredentials creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, applicationId, secretKey).Result;

AdlsClient adlsClient = AdlsClient.CreateClient(adlsAccountName, creds);
string srcPath = @"/InputFiles/1636274001230002_20180621_104427.json";
using (StreamReader readStream = new 
StreamReader(adlsClient.GetReadStream(srcPath)))
        {
            var p2Object = JsonConvert.DeserializeObject(readStream.ReadToEnd());
            results = JObject.Parse(p2Object.ToString());
        }

        date = ((string)results["eeData"][0]["startDate"]);
        machine = ((string)results["eeData"][0]["machineName"]);
        ppl = ((string)results["eeData"][0]["ppl"]);

The issue is with the reference path missing in SSIS Script component for the 3rd party DLLs. 问题在于第三方DLL的SSIS脚本组件中缺少引用路径。 In Console App I am able to install NuGet package manager. 在控制台应用程序中,我可以安装NuGet软件包管理器。 But in SSIS Script component, the NuGet package installation is failed and SSIS component is missing the reference. 但是在SSIS脚本组件中,NuGet软件包安装失败,并且SSIS组件缺少参考。 The below code will force the script component compiler to refer the DLLs from the given path. 下面的代码将强制脚本组件编译器从给定路径引用DLL。

Add this code above PreExecute() / Main() method. 将此代码添加到PreExecute()/ Main()方法上方。

static ScriptMain()
    {
        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    }

    static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (args.Name.Contains("Newtonsoft.Json"))
        {
            return System.Reflection.Assembly.LoadFile(@"C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\ToolsRef\Newtonsoft.Json.dll");
        }

        if (args.Name.Contains("Microsoft.Azure.DataLake.Store"))
        {
            return System.Reflection.Assembly.LoadFile(@"C:\Program Files\WindowsPowerShell\Modules\AzureRM.DataLakeStore\5.2.0\Microsoft.Azure.DataLake.Store.dll");
        }

        if (args.Name.Contains("Microsoft.Rest.ClientRuntime.Azure.Authentication"))
        {
            return System.Reflection.Assembly.LoadFile(@"C:\Program Files\WindowsPowerShell\Modules\Azure\5.1.2\StorSimple\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll");
        }

        if (args.Name.Contains("Microsoft.Rest.ClientRuntime"))
        {
            return System.Reflection.Assembly.LoadFile(@"C:\Program Files\WindowsPowerShell\Modules\Azure\5.1.2\Services\Microsoft.Rest.ClientRuntime.dll");
        }
       if (args.Name.Contains("NLog"))
        {
        return System.Reflection.Assembly.LoadFile(@"C:\Users\<user>\source\repos\Integration Services Project2\NLog.dll");
        }

        return null;

       }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SSIS组件-Azure Data Lake Store源无法加载平面文件 - SSIS component - Azure Data Lake Store Source failing to load a flat file 使用rest api的azure数据湖存储中的更新文件出现问题 - issue with update file in azure data lake store using rest api 使用Azure Data Lake Store Gen1中的SSIS包将文件从一个目录移动到另一个目录 - Move Files from one directory to another using SSIS Package in Azure Data Lake Store Gen1 无法通过 SSIS 连接到 Azure 数据湖存储 - Unable to connect to Azure data lake store via SSIS 如何从Azure Data Lake Store中读取Azure Databricks中的JSON文件 - How to read a JSON file in Azure Databricks from Azure Data Lake Store Azure 数据湖 - 使用 Python 读取 - Azure data lake - read using Python 使用Azure Data Factory将数据从Data Lake Store(JSON文件)移动到Azure搜索 - Move data from Data Lake Store (JSON file ) to Azure Search using Azure Data Factory 如何使用来自Azure文件共享的多个线程将数据复制到Azure Data Lake存储? - How to copy data to Azure Data Lake store using multiple threads from azure file share? 读取 Azure Data Lake Store 中文件的元数据 - Read Meta Data of files inside Azure Data Lake Store Azure Data Lake存储通过C#脚本创建文件夹 - Azure Data Lake store create folder via C# script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM