Copy From OnPrem SQL server to DocumentDB using custom activity in ADF Pipeline

后端 未结 4 697
予麋鹿
予麋鹿 2021-01-24 09:56

I am trying to copy data from SQL Table in a on-prem sql server and upload it to a Document DB using custom activity in Azure data factory pipeline. Can anyone tell me how can I

4条回答
  •  忘了有多久
    2021-01-24 10:30

    I was able to solve the problem. The solution is to write the code in custom activity itself that copies data from On-Prem SQL Server to DocumentDB by using the below code:

     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;
            }
        }
    

提交回复
热议问题