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