1

Import data from a SQL Database hosted on Azure virtual machine, convert sql query data as a json document and store it in Azure Data Lake Storage. I am using powershell to create the json document.

Hit a roadblock on how to import json documents into data lake store and to automate the import.

$InstanceName = "SQLDB\TST"
$connectionString = "Server=$InstanceName;Database=dbadb;Integrated Security=True;"
$query = "SELECT * FROM Employee"
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString

$connection.Open()

$command = $connection.CreateCommand()
$command.CommandText = $query
$result = $command.ExecuteReader()
$table = new-object "System.Data.DataTable"
$table.Load($result)
$table | select $table.Columns.ColumnName | ConvertTo-Json | Set-Content "C:\JsonDocs\result.json"

$connection.Close()
paone
  • 828
  • 8
  • 18

1 Answers1

1

If you want to store JSON file in Azure data lake store with PowerShell, you can use the PowerShell command Import-AzDataLakeStoreItem

For example

Connect-AzAccount
Import-AzDataLakeStoreItem -AccountName $dataLakeStorageGen1Name `
   -Path "you json file path" `
   -Destination "the path in data lake store"

For more details, please refer to the document

Jim Xu
  • 21,610
  • 2
  • 19
  • 39