Azure Logic Apps – Blob Trigger to SQL Integration

Azure Logic Apps: Trigger on Blob Event, Filter Content & Insert into SQL

🔹 Step 1: Create a Logic App

  1. Go to Azure Portal & search for Logic Apps.
  2. Click “Create” → Choose “Logic App (Consumption)”.
  3. Set the resource group, name, and region.
  4. Click “Review + Create” and then “Create”.

🔹 Step 2: Start with Blob Trigger

  1. Open the Logic App Designer.
  2. Choose the trigger: “When a blob is added or modified (properties only)”.
  3. Sign in to connect your storage account.
  4. Select:
    • Storage account
    • Container (e.g., studentdata)

🔹 Step 3: Get Blob Content

  1. Click “+ New Step”.
  2. Add action: “Get blob content using path”.
  3. Set:
    • Blob path = dynamic value: Path
    • Storage account connection = same as before

🔹 Step 4: Parse Blob Content (Assume JSON)

  1. Add action: “Parse JSON”.
  2. Content = Blob content from previous step.
  3. Generate schema by uploading or pasting a sample. For example:

[
  {
    "Name": "John",
    "RollNumber": 101,
    "TotalMarks": 85
  },
  {
    "Name": "Jane",
    "RollNumber": 102,
    "TotalMarks": 40
  }
]
    

🔹 Step 5: Add Condition to Filter Records

  1. Add action: “For Each” loop → Parse JSON - Body.
  2. Inside the loop, add “Condition”:
  3. Set condition:
    • item()?['TotalMarks'] is greater than 50
  4. Inside the "If yes" branch, continue to next step.

🔹 Step 6: Insert into SQL Server

  1. Add action: “SQL Server – Insert row (V2)”.
  2. Sign in to connect to your Azure SQL or on-prem SQL with gateway.
  3. Select:
    • Server & Database
    • Table (e.g., Students)
  4. Map fields from parsed JSON:
    • Name → item()?['Name']
    • RollNumber → item()?['RollNumber']
    • TotalMarks → item()?['TotalMarks']

🔹 Step 7: Finalize & Save

  • Save your Logic App and run a test by uploading a blob JSON file into the container.
  • Only records with TotalMarks > 50 will be inserted into SQL Server.

📦 Blob Upload Sample (in .NET)


public async Task UploadStudentBlobAsync(Student student)
{
    var json = JsonConvert.SerializeObject(student);
    var client = new BlobContainerClient(connectionString, "studentdata");
    var blob = client.GetBlobClient($"{student.RollNumber}.json");

    using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
    await blob.UploadAsync(stream, overwrite: true);
}
    

📊 Sample SQL Table Schema


CREATE TABLE Students (
    Id INT IDENTITY PRIMARY KEY,
    Name NVARCHAR(100),
    RollNumber INT,
    TotalMarks INT
);
    

🎯 What You Achieved

  • Created a Logic App to listen for blob uploads
  • Parsed JSON content and filtered based on Total Marks
  • Inserted filtered records into a SQL table