---
title: "SQL-002: Retrieve inbound context rows"
summary: Retrieves context rows left by a source application for the current application and session, excluding the current application's own rows.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-002: Retrieve inbound context rows

Reads every context row a source application saved for the current session, filtered to exclude rows the current application wrote itself. Called by `clsContext.RetrieveContext`, which is invoked from `clsControllerBase.CheckContext` only when the request's referrer application differs from the current application.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-002 |
| **Operation type** | Read |
| **Execution method** | Inline SQL (VB `& _` string concatenation), `CommandType.Text`, `SqlDataAdapter.Fill` |
| **Database** | SQL Server |
| **Schema** | `[unqualified]`** |
| **Command type** | Text |
| **Business object** | `clsContext.clsContextRepository` |
| **Criteria property** | N/A — not a BOF `IBusinessCriteria` object; SQL is held in the private `clsSQL` helper class |
| **Lifecycle method** | `clsContextRepository.Retrieve(SourceAppName, CurrentAppName, inSessionID)` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@AppName` | Input | `SqlDbType.VarChar` | 50 | **Source** application whose context rows are being handed over |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | ASP.NET session ID |
| `@CurrentApp` | Input | `SqlDbType.VarChar` | 50 | **Current** application name; rows written by the current app are excluded via `not AppName = @CurrentApp` |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [Context](../database-tables.md#context) | SELECT | `ID`, `AppName`, `SessionID`, `ContextName`, `ContextValue`, `UpdateDate` |

## Sample SQL

```sql
SELECT
  ID,
  AppName,
  SessionID,
  ContextName,
  ContextValue,
  UpdateDate
FROM Context
WHERE AppName = @AppName
  and SessionID = @SessionID
  and not AppName = @CurrentApp
```

## Operations and processes
- [Retrieve and consume context rows](../operations/retrieve-context-rows.md)
- [Receive inbound cross-application context](../operations/receive-inbound-context.md)

## Business rules
- [BR-MVC-010: Every navigation records source/target app and view](../business-rules.md#br-mvc-010-every-navigation-records-sourcetarget-app-and-view)
- [BR-MVC-017: Cross-application context is consumed exactly once](../business-rules.md#br-mvc-017-cross-application-context-is-consumed-exactly-once)
- [BR-MVC-019: Context persistence targets database APPM under tag NETFRAMEWORK](../business-rules.md#br-mvc-019-context-persistence-targets-database-appm-under-tag-netframework)

> **Note:** Statements marked with `**` could not be confirmed; treat as unknown until verified.

## Sources
- SAIF.Presentation.Web.MVC/clsContext.vb
