ADF - C # Custom Activity

大憨熊 提交于 2019-12-10 11:13:47

问题


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


回答1:


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 ();


来源:https://stackoverflow.com/questions/37673105/adf-c-custom-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!