---
title: "SQL-MVC-002: Retrieve cross-application context"
summary: Retrieves context rows left by a different source application for the current session.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-MVC-002: Retrieve cross-application context

Reads all context rows a different source application left behind for the current session, explicitly excluding rows already belonging to the current application. `clsContext.RetrieveContext` calls this, then immediately deletes the returned rows via [SQL-MVC-004](SQL-MVC-004-delete-context-rows.md) — a read-then-consume pattern that implements a one-time cross-application state hand-off.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-MVC-002 |
| **Operation type** | Read |
| **Execution method** | Inline SQL (`SqlCommand` + `SqlDataAdapter.Fill`) |
| **Database** | SQL Server (catalog `NETFRAMEWORK`) |
| **Schema** | `[unqualified]**` |
| **Command type** | Text |
| **Business object** | N/A (Application layer) |
| **Criteria property** | N/A (Application layer) |
| **Lifecycle method** | N/A (Application layer) |
| **Application class** | `clsContext.clsContextRepository.Retrieve(SourceAppName, CurrentAppName, inSessionID)` — called from `clsContext.RetrieveContext` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@AppName` | Input | `SqlDbType.VarChar` | 50 | Source application name to match; bound from `SourceAppName`. |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | Session identifier to match; bound from `inSessionID`. |
| `@CurrentApp` | Input | `SqlDbType.VarChar` | 50 | Current (calling) application name, used to *exclude* rows via `not AppName=@CurrentApp`; bound from `CurrentAppName`. |

## Tables

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

## Sample SQL

```sql
-- Retrieve context rows left by a different source application for this session
SELECT
  ID,
  AppName,
  SessionID,
  ContextName,
  ContextValue,
  UpdateDate
FROM Context
WHERE AppName = @AppName
  AND SessionID = @SessionID
  AND not AppName = @CurrentApp
```

## Operations and processes
- [Cross-application context hand-off](../operations/cross-application-context-hand-off.md)

## Business rules
- [BR-MVC-005: Cross-application context transfer only across distinct applications](../business-rules.md#br-mvc-005-cross-application-context-transfer-only-across-distinct-applications)

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

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