Tutorials ADO.NET Core Tutorial

Streaming Data — Complete Guide

Streaming Data — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.

On this page

ADO.NET Core Tutorial · Lesson 46 of 100

Streaming Data

Foundations ✓SQL & safetyProductionProjects

SQL & safety · 2 — Procs, tx, performance · ~6 min · Module 5: Performance Optimization

What is this?

Stream query results to HTTP with IAsyncEnumerable or pipes so memory stays flat.

Why should you care?

ShopNest exports of 2M order lines must stream.

See it live — copy this example

Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.

async IAsyncEnumerable<OrderDto> StreamAsync([EnumeratorCancellation] CancellationToken ct)
{
  await using var conn = new SqlConnection(cs);
  await conn.OpenAsync(ct);
  await using var cmd = new SqlCommand("SELECT Id, Total FROM Orders", conn);
  await using var r = await cmd.ExecuteReaderAsync(ct);
  while (await r.ReadAsync(ct))
    yield return new OrderDto(r.GetInt32(0), r.GetDecimal(1));
}

What happened?

  • yield return from reader.
  • Minimal APIs can return IAsyncEnumerable.
  • Keep connection alive for the stream lifetime carefully.

Practice next

  1. build StreamAsync.
  2. Consume with await foreach.
  3. Cancel mid-stream.
  4. Map more columns.
  5. Write CSV while streaming.

Remember

IAsyncEnumerable streams. Don’t buffer all. Honor cancellation.

ShopNest export endpoint

GET /exports/orders streams DTOs.

Outcome: Memory flat at millions of rows.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
SqlCommand: Used for SQL Server databases. It represents a Transact-SQL?
Short answer: command or stored procedure. Example: SqlCommand command = new SqlCommand(&quot;SELECT * FROM Customers&quot;, connection); Example code command or stored procedure. Example: SqlCommand command = new SqlCom…
Mid PDF Detailed
OleDbCommand: Used for databases that support OLE DB providers (e.g., MS?
Short answer: Access, Oracle). Example: OleDbCommand command = new OleDbCommand(&quot;SELECT * FROM Customers&quot;, connection); Example code Access, Oracle). Example: OleDbCommand command = new OleDbCommand(&quot;SELEC…
Mid PDF Detailed
Use Paging: Instead of loading all the records at once, retrieve data in chunks (or pages) using SQL's LIMIT, OFFSET, or TOP clauses. You can implement paging on both the server side (in the SQL query) and the client side (in the ASP.NET
Short answer: pplication). Example (Using Paging in SQL): string query = &quot;SELECT * FROM Customers ORDER BY CustomerID OFFSET @Offset ROWS FETCH NEXT @PageSize ROWS ONLY&quot;; SqlCommand command = new SqlCommand(que…
Mid PDF Detailed
In both examples, we retrieve a single row or column of data based on a condition (in this?
Short answer: case, a CustomerID). Practical/Scenario-Based ADO.NET Questions Say this in the interview Define — one clear sentence (the short answer above). Example — relate it to a project like ShopNest or your real wo…
Mid PDF Detailed
Bind the data to the GridView. Example: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection connection = new SqlConnection(connectionString); SqlDataAdapter adapter = new SqlDataAdapter("SELECT CustomerID, CustomerName FROM Customers", connection); DataTable dataTable = new DataTable();
Short answer: dapter.Fill(dataTable); GridView1.DataSource = dataTable; GridView1.DataBind(); } } Here, GridView1 is bound to the data returned from the SQL query (SELECT CustomerID, CustomerName FROM Customers), and the…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

ADO.NET Core Tutorial
Course syllabus

ADO.NET Core Tutorial

Module 1: ADO.NET Fundamentals
Module 2: CRUD Operations
Module 3: Stored Procedures
Module 4: Transactions and Error Handling
Module 5: Performance Optimization
Module 6: ASP.NET Core Integration
Module 7: Advanced Enterprise Topics
Module 8: Testing and Debugging
Module 9: Cloud and DevOps
Module 10: Real-World Enterprise Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details