ADF-C#自定义活动 [英] ADF - C # Custom Activity
问题描述
我有一个csv文件作为输入,已存储在Azure Blob存储中.我想从csv文件读取数据,对其进行一些转换,然后将数据存储在Azure SQL数据库中.我试图在Azure数据工厂中使用C#自定义活动,将blob作为输入,将sql表作为输出数据集.我正在按照本教程进行操作( https://azure.microsoft.com/zh-CN/documentation/articles/data-factory-use-custom-activities/#see-also ),但它同时具有输入和输出(斑点)的形式.我无法获取如何为SQL数据库获取一些示例代码作为输出.谢谢
I have a csv file as input which I have stored in Azure Blob Storage. I want to read data from csv file, perform some transformations on it and then store data in Azure SQL Database. I am trying to use a C# custom activity in Azure Data Factory having blob as input and sql table as output dataset. I am following this tutorial (https://azure.microsoft.com/en-us/documentation/articles/data-factory-use-custom-activities/#see-also) but it has both input and output as blobs. Can I get some sample code for sql database as output as I am unable to figure out how to do it. Thanks
推荐答案
您只需要从链接的服务中获取Azure SQL数据库的连接字符串,然后就可以与数据库进行通讯了.尝试以下示例代码:
You just need to fetch connection string of your Azure SQL database from a linked service and then you can talk to database. Try this sample code:
AzureSqlDatabaseLinkedService sqlInputLinkedService;
AzureSqlTableDataset sqlInputLocation;
Dataset sqlInputDataset = datasets.Where(dataset => dataset.Name == "<Dataset Name>").First();
sqlInputLocation = sqlInputDataset.Properties.TypeProperties as AzureSqlTableDataset;
sqlInputLinkedService = linkedServices.Where (
linkedService =>
linkedService.Name ==
sqlInputDataset.Properties.LinkedServiceName).First().Properties.TypeProperties
as AzureSqlDatabaseLinkedService;
SqlConnection connection = new SqlConnection(sqlInputLinkedService.ConnectionString);
connection.Open ();
这篇关于ADF-C#自定义活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!