---
title: "SQL-MVC-001: Insert context value"
summary: Inserts one cross-application context key/value row for the current application and session.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# SQL-MVC-001: Insert context value

Persists a single cross-application context key/value pair (e.g., claim ID, policy number) for the current application and session into the `Context` table. `clsContext.SaveContext` calls this once per key in `m_AppVars`, after first deleting any prior rows for the same application/session via [SQL-MVC-004](SQL-MVC-004-delete-context-rows.md) (a delete-then-reinsert "upsert via replace" pattern).

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-MVC-001 |
| **Operation type** | Create |
| **Execution method** | Inline SQL (`SqlCommand.ExecuteNonQuery`) |
| **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.Save(inAppName, inSessionID, inContextName, inContextValue)` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `@AppName` | Input | `SqlDbType.VarChar` | 50 | Application name owning the context row; bound from `inAppName`. |
| `@SessionID` | Input | `SqlDbType.VarChar` | 50 | ASP.NET session identifier the context value belongs to; bound from `inSessionID`. |
| `@ContextName` | Input | `SqlDbType.VarChar` | 50 | Name/key of the context variable being persisted; bound from `inContextName`. |
| `@ContextValue` | Input | `SqlDbType.VarChar` | 256 | String value of the context variable; bound from `inContextValue`. |

Note: the SQL text supplies 5 values but only 4 parameters are bound — the 5th column value is the literal `CURRENT_TIMESTAMP`, populating the `UpdateDate` column with the server's current timestamp at insert time (not a bound parameter).

## Tables

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

## Sample SQL

```sql
-- Insert one context key/value row for the current application/session
Insert into Context
Values
(@AppName, @SessionID, @ContextName, @ContextValue, CURRENT_TIMESTAMP)
```

## Operations and processes
- [Cross-application navigation](../operations/cross-application-navigation.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
