---
title: "SQL-001: Insert a context row"
summary: Inserts a single context key/value row for the source application and session.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-001: Insert a context row

Writes one context key/value pair into the `Context` table on behalf of `clsContext.SaveContext`. The method is called once per key held in the in-memory context hashtable, so a single navigation that carries several values (target app, target view, claim ID, etc.) executes this statement multiple times after first clearing prior rows with [SQL-004](SQL-004-delete-context-rows.md).

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-001 |
| **Operation type** | Create |
| **Execution method** | Inline SQL (VB `& _` string concatenation), `CommandType.Text`, `ExecuteNonQuery` |
| **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.Save` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@AppName` | Input | `SqlDbType.VarChar` | 50 | Owning application name (`clsContext.m_ApplicationName`) whose context values are being written |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | ASP.NET session ID supplied by `clsControllerBase` (`m_HttpContext.Session.SessionID`) |
| `@ContextName` | Input | `SqlDbType.VarChar` | 50 | Context key from the in-memory `m_AppVars` hashtable — e.g. `targetView`, `targetApp`, `sourceApp`, `sourceView`, `claimId`, `policyNum`, `SAIFClaimNum`, `ProviderLocationSeqNum`, `__SAIFPID` |
| `@ContextValue` | Input | `SqlDbType.VarChar` | 256 | Context value, always persisted as a string |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [Context](../database-tables.md#context) | INSERT | `AppName`, `SessionID`, `ContextName`, `ContextValue`, `UpdateDate` (positional; no explicit column list) |

## Sample SQL

```sql
-- Positional insert with no explicit column list; bound to the physical column order of Context
Insert into Context
Values (
  @AppName,
  @SessionID,
  @ContextName,
  @ContextValue,
  CURRENT_TIMESTAMP)
```

## Operations and processes
- [Persist context rows](../operations/persist-context-rows.md)
- [Navigate to a view](../operations/navigate-to-view.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-011: Context is persisted only on genuine cross-app transitions](../business-rules.md#br-mvc-011-context-is-persisted-only-on-genuine-cross-app-transitions)
- [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
