---
title: "SQL-003: Retrieve a single context value by name"
summary: Retrieves one context value for a session and context-name key, used to recover the multi-model view ID (__SAIFPID).
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-003: Retrieve a single context value by name

Fetches a single context value for a session, keyed by context name. In practice this statement is called only from `clsContext.GetPID`, with `ContextName` fixed to `ViewPageBase.SAIFPID_NAME` (`__SAIFPID`), to recover the multi-model view ID a postback should rejoin.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-003 |
| **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(inSessionID, inContextValue)` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | ASP.NET session ID |
| `@ContextName` | Input | `SqlDbType.VarChar` | 50 | Context key to fetch; called only with `ViewPageBase.SAIFPID_NAME` to recover the page/view instance ID |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [Context](../database-tables.md#context) | SELECT | `ContextValue` |

## Sample SQL

```sql
Select
  ContextValue
FROM Context
Where SessionID = @SessionID
  and ContextName = @ContextName
```

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

## Business rules
- [BR-MVC-008: Multi-model view state is keyed by a per-view GUID](../business-rules.md#br-mvc-008-multi-model-view-state-is-keyed-by-a-per-view-guid)
- [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
