---
title: "SQL-MVC-003: Retrieve single context value by session and name"
summary: Looks up a single named context value for a session, used to resolve the current page/view ID.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-MVC-003: Retrieve single context value by session and name

Looks up a single context value by session ID and context name. Used by `clsContext.GetPID`, which is invoked from `clsControllerBase.CheckContextViewID()` to resolve the "page ID" (`SAIFPID_NAME`) context value for the current session.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-MVC-003 |
| **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(inSessionID, inContextValue)` — called from `clsContext.GetPID` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | Session identifier to match; bound from `inSessionID`. |
| `@ContextName` | Input | `SqlDbType.VarChar` | 50 | Context variable name to look up (the `SqlParameter` is named `@ContextName` while the calling method's argument is named `inContextValue` — a source-level naming inconsistency, not a functional issue); used by `clsContext.GetPID` to fetch a single named context value (e.g., `SAIFPID_NAME`). |

## Tables

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

## Sample SQL

```sql
-- Retrieve a single named context value for the given session (e.g., SAIFPID_NAME)
Select ContextValue
FROM Context
Where SessionID = @SessionID
  AND ContextName = @ContextName
```

## Operations and processes
- [Page/control lifecycle initialization](../operations/page-control-lifecycle-initialization.md)

## Business rules

No business rule directly governs this statement — it is a simple existence check (`If dt.Rows.Count = 1`) with no error/contention handling; the caller returns `""` when no row is found.

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

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