Sql server 使用ADF管道中的自定义活动从OnPrem SQL server复制到DocumentDB
我正在尝试从on prem SQL server中的SQL表复制数据,并使用Azure data factory管道中的自定义活动将其上载到文档数据库。有谁能告诉我如何使用IDotNetActivity或任何其他接口或类来完成此任务。我将此功能用于常规Azure Data Factory(ADF)任务。不需要自定义任务。我不会让事情变得比需要的更复杂,尤其是这些组件可能很难调试 以下示例显示:Sql server 使用ADF管道中的自定义活动从OnPrem SQL server复制到DocumentDB,sql-server,azure,azure-data-factory,custom-activity,Sql Server,Azure,Azure Data Factory,Custom Activity,我正在尝试从on prem SQL server中的SQL表复制数据,并使用Azure data factory管道中的自定义活动将其上载到文档数据库。有谁能告诉我如何使用IDotNetActivity或任何其他接口或类来完成此任务。我将此功能用于常规Azure Data Factory(ADF)任务。不需要自定义任务。我不会让事情变得比需要的更复杂,尤其是这些组件可能很难调试 以下示例显示: 类型的链接服务 类型的链接服务 类型为的输入数据集 类型的输出数据集 具有使用和的复制活动的 本地SQ
{
"name": "OnPremLinkedService",
"properties": {
"type": "OnPremisesSqlServer",
"description": "",
"typeProperties": {
"connectionString": "Data Source=<servername - required for credential encryption>;Initial Catalog=<databasename - required for credential encryption>;Integrated Security=False;User ID=<username>;Password=<password>;",
"gatewayName": "<Name of the gateway that the Data Factory service should use to connect to the on-premises SQL Server database - required for credential encryption>",
"userName": "<Specify user name if you are using Windows Authentication>",
"password": "<Specify password for the user account>"
}
}
}
DocumentDbCollection类型的输出数据集:
{
"name": "PersonDocumentDbTableOut",
"properties": {
"structure": [
{
"name": "Id",
"type": "Int32"
},
{
"name": "Name.First",
"type": "String"
},
{
"name": "Name.Middle",
"type": "String"
},
{
"name": "Name.Last",
"type": "String"
}
],
"published": false,
"type": "DocumentDbCollection",
"linkedServiceName": "DocumentDbLinkedService",
"typeProperties": {
"collectionName": "Person"
},
"availability": {
"frequency": "Day",
"interval": 1
}
}
}
使用SqlSource和DocumentDBCollectionLink执行复制活动的管道:
{
"name": "PipelineTemplate 3",
"properties": {
"description": "On prem to DocDb test",
"activities": [
{
"type": "Copy",
"typeProperties": {
"source": {
"type": "SqlSource"
},
"sink": {
"type": "DocumentDbCollectionSink",
"writeBatchSize": 2,
"writeBatchTimeout": "00:00:00"
},
"translator": {
"type": "TabularTranslator",
"columnMappings": "id: id, FirstName: Name.First, MiddleName: Name.Middle, LastName: Name.Last"
}
},
"inputs": [
{
"name": "SQLServerDataset"
}
],
"outputs": [
{
"name": "PersonDocumentDbTableOut"
}
],
"policy": {
"timeout": "1.00:00:00",
"concurrency": 1,
"retry": 3
},
"scheduler": {
"frequency": "Day",
"interval": 1
},
"name": "CopyActivityTemplate"
}
],
"start": "2016-10-05T00:00:00Z",
"end": "2016-10-05T00:00:00Z",
"isPaused": false,
"hubName": "adfdocdb2_hub",
"pipelineMode": "Scheduled"
}
}
我得到这个是为了配合传统的Azure数据工厂(ADF)任务。不需要自定义任务。我不会让事情变得比需要的更复杂,尤其是这些组件可能很难调试 以下示例显示:
{
"name": "OnPremLinkedService",
"properties": {
"type": "OnPremisesSqlServer",
"description": "",
"typeProperties": {
"connectionString": "Data Source=<servername - required for credential encryption>;Initial Catalog=<databasename - required for credential encryption>;Integrated Security=False;User ID=<username>;Password=<password>;",
"gatewayName": "<Name of the gateway that the Data Factory service should use to connect to the on-premises SQL Server database - required for credential encryption>",
"userName": "<Specify user name if you are using Windows Authentication>",
"password": "<Specify password for the user account>"
}
}
}
DocumentDbCollection类型的输出数据集:
{
"name": "PersonDocumentDbTableOut",
"properties": {
"structure": [
{
"name": "Id",
"type": "Int32"
},
{
"name": "Name.First",
"type": "String"
},
{
"name": "Name.Middle",
"type": "String"
},
{
"name": "Name.Last",
"type": "String"
}
],
"published": false,
"type": "DocumentDbCollection",
"linkedServiceName": "DocumentDbLinkedService",
"typeProperties": {
"collectionName": "Person"
},
"availability": {
"frequency": "Day",
"interval": 1
}
}
}
使用SqlSource和DocumentDBCollectionLink执行复制活动的管道:
{
"name": "PipelineTemplate 3",
"properties": {
"description": "On prem to DocDb test",
"activities": [
{
"type": "Copy",
"typeProperties": {
"source": {
"type": "SqlSource"
},
"sink": {
"type": "DocumentDbCollectionSink",
"writeBatchSize": 2,
"writeBatchTimeout": "00:00:00"
},
"translator": {
"type": "TabularTranslator",
"columnMappings": "id: id, FirstName: Name.First, MiddleName: Name.Middle, LastName: Name.Last"
}
},
"inputs": [
{
"name": "SQLServerDataset"
}
],
"outputs": [
{
"name": "PersonDocumentDbTableOut"
}
],
"policy": {
"timeout": "1.00:00:00",
"concurrency": 1,
"retry": 3
},
"scheduler": {
"frequency": "Day",
"interval": 1
},
"name": "CopyActivityTemplate"
}
],
"start": "2016-10-05T00:00:00Z",
"end": "2016-10-05T00:00:00Z",
"isPaused": false,
"hubName": "adfdocdb2_hub",
"pipelineMode": "Scheduled"
}
}
我能解决这个问题。解决方案是在自定义活动本身中编写代码,使用以下代码将数据从Prem SQL Server复制到DocumentDB:
public async Task CopyDataFromTo(string source)
{
try
{
DataTable dtSource = new DataTable();
string EndpointUrl = "https://yourendpoint.documents.azure.com:443/";
string AuthorizationKey = "*****";
SecureString authKey = new SecureString();
foreach(char c in AuthorizationKey.ToCharArray())
{
authKey.AppendChar(c);
}
SqlDataAdapter adapSource = new SqlDataAdapter("Select * From YourTable", source);
adapSource.Fill(dtSource);
foreach (DataRow Dr in dtSource.Rows)
{
dynamic docFirst = new
{
UserID = Int32.Parse(Dr["ColumnOne"].ToString()),
UserAlias = Dr["ColumnTwo"].ToString()
};
using (var client = new DocumentClient(new Uri(EndpointUrl), authKey))
{
Document newDocument = await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("DatabaseName", "CollectionName"), docFirst);
};
}
}
catch (Exception Ex)
{
throw Ex;
}
}
我能解决这个问题。解决方案是在自定义活动本身中编写代码,使用以下代码将数据从Prem SQL Server复制到DocumentDB:
public async Task CopyDataFromTo(string source)
{
try
{
DataTable dtSource = new DataTable();
string EndpointUrl = "https://yourendpoint.documents.azure.com:443/";
string AuthorizationKey = "*****";
SecureString authKey = new SecureString();
foreach(char c in AuthorizationKey.ToCharArray())
{
authKey.AppendChar(c);
}
SqlDataAdapter adapSource = new SqlDataAdapter("Select * From YourTable", source);
adapSource.Fill(dtSource);
foreach (DataRow Dr in dtSource.Rows)
{
dynamic docFirst = new
{
UserID = Int32.Parse(Dr["ColumnOne"].ToString()),
UserAlias = Dr["ColumnTwo"].ToString()
};
using (var client = new DocumentClient(new Uri(EndpointUrl), authKey))
{
Document newDocument = await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("DatabaseName", "CollectionName"), docFirst);
};
}
}
catch (Exception Ex)
{
throw Ex;
}
}
实际上,定制活动现在无法访问prem数据 类似问题如下: 解决方案是将prem数据拷贝到云。然后针对云存储运行自定义活动。wBob分享了上面的好样本
如果您必须在一个活动中完成它,您可以设置vNet和ExpressRoute以将Azure公共云连接到onprem环境。实际上,自定义活动目前无法访问prem数据 类似问题如下: 解决方案是将prem数据复制到云。然后针对云存储运行自定义活动。wBob分享了上面的好样本
如果您必须在一个活动中完成,您可以设置vNet和ExpressRoute以将Azure公共云连接到onprem环境。谢谢。结果证明你是对的。我实施的解决方案是: 第1部分: 实现了一个数据工厂管道,将数据从on-prem数据库移动到staging DocumentDB集合 第2部分:
使用自定义活动组合documentdb中不同集合(分段)的数据,以创建具有所需输出数据的新documentdb集合。谢谢。结果证明你是对的。我实施的解决方案是: 第1部分: 实现了一个数据工厂管道,将数据从on-prem数据库移动到staging DocumentDB集合 第2部分:
使用自定义活动组合documentdb中不同集合(暂存)的数据,以创建具有所需输出数据的新documentdb集合。此详细信息用于将blob存储复制到documentdb。看看你是否可以让它工作,然后适应on-prem数据源。谢谢你的回复,但我正在尝试使用自定义活动进行复制。这详细介绍了从blob存储复制到DocumentDB的过程。看看你是否能让它正常工作,然后适应on-prem数据源。谢谢你的回复,但我正在尝试使用自定义活动进行复制。我能够让它与wBob提到的ADF配置一起工作。然而,要求是使用自定义活动来完成它。这很有趣。您能解释一下为什么必须使用自定义活动吗?根据经验,当出现问题时,这些任务很难调试,所以使用内置任务进行调试通常更可取。有兴趣了解更多关于您的用例的信息。谢谢。wBob关于调试的困难,你是对的。目前,该项目处于初级阶段。将在这里更新为什么我们需要定制活动和项目后期的业务需要。感谢您的快速回复。我能够让它与wBob提到的ADF配置一起工作。然而,要求是使用自定义活动来完成它。这很有趣。您能解释一下为什么必须使用自定义活动吗?根据经验,当出现问题时,这些任务很难调试,所以使用内置任务进行调试通常更可取。有兴趣了解更多关于您的用例的信息。谢谢。wBob关于调试的困难,你是对的。目前,该项目处于初级阶段。将在这里更新为什么我们需要定制活动和项目后期的业务需要。谢谢你的快速回复。