Stored procedures still run only on the server, so a "disconnected" client can't invoke one directly. You call it through a short-lived connection — or through a service layer that owns the connection — then work with the returned data locally. In the classic ADO.NET pattern, that means SqlDataAdapter with a DataTable and a DataConfiguration setup; in modern systems it usually means a Web API wrapper around SqlCommand. The key condition: define what "disconnected" means in your app (brief connection vs. fully offline) before choosing the pattern.
The phrase "disconnected architecture" gets used for two very different situations, and mixing them up is the usual cause of broken code. In one, the application opens a database connection just long enough to execute the procedure, copies the results into an in-memory object, and closes the connection before any UI binding or business logic touches the data. In the other, the client has no database connectivity at all for stretches of time — a mobile field app, a kiosk, a desktop tool used on a plane — and must queue work until a network path returns. Both are "disconnected," but only the first lets you call the procedure more or less directly. The second requires a request-and-replay design where the procedure call happens later, on a server or gateway that does have a connection.
Everything below assumes you know the procedure's name, its parameters, and whether it returns rows, a scalar, output parameters, or just a row count. If it doesn't, get that contract from whoever owns the database first; guessing parameter order is how you end up debugging a silent NULL.
What "Disconnected" Actually Means for a Procedure Call
A stored procedure executes inside the database engine. It cannot execute in your DataSet, your Entity Framework change tracker, or your browser. So the disconnected model never removes the call — it removes the duration of the connection and the coupling between the data and the live database.
In ADO.NET terms, the disconnected layer is the DataSet/DataTable family plus the DataAdapter. The adapter is a small bridge object that knows how to open a connection, run a command, fill a table, and (optionally) push changes back. You configure it with up to four commands — SelectCommand, InsertCommand, UpdateCommand, DeleteCommand — and the first of those is where your procedure call lives. Once Fill returns, the adapter, connection, and command can all be disposed while the DataTable lives on in memory, binding to a grid, getting filtered, or being serialized.
In service-oriented terms, the disconnected layer is an HTTP endpoint or message queue. The client sends a request, the API opens a connection, calls the procedure, maps the result to a DTO, and returns JSON. The client's "disconnection" is from SQL Server, not from the application's own back end.
If your app has literally no connectivity — not even to your own API — then you're in the second category, and the procedure call becomes part of a deferred sync operation. That's a different design and gets its own section below.
Prerequisites Before You Write the Call
Check these off before touching code, because each one turns into a confusing runtime error if it's wrong:
Connection string with the right auth. Integrated security vs. SQL auth changes nothing about the procedure call but everything about why it fails. Store it in configuration, not source. Execute permission. The login or user needs EXECUTE on the procedure (or on its schema). A SELECT-only account will fail even if the procedure only reads. Parameter contract. Name, type, size, direction (Input, Output, InputOutput, ReturnValue), and whether any are nullable. Note whether the procedure returns multiple result sets. Result shape. Zero rows is not an error; a missing result set is. Know the difference before you write error handling. Provider package. Microsoft.Data.SqlClient is the current SQL Server provider; System.Data.SqlClient is the older one still found in legacy code. For other engines, the equivalent is MySqlConnector, Npgsql, Microsoft.Data.Sqlite, and so on — the pattern is the same, the class names differ.
One detail that trips people up: if the procedure uses SET NOCOUNT ON, the row-count messages disappear, which is usually what you want when filling a DataTable. If it doesn't, ADO.NET handles the extra result sets fine, but some ORMs and manual NextResult() loops need to account for them.
Step-by-Step: Calling a Procedure with a DataAdapter
This is the canonical disconnected call. It assumes a procedure named dbo.GetOrdersByCustomer that takes @CustomerId and returns a result set.
1: Create the connection. Use using so it disposes deterministically: using var conn = new SqlConnection(cs); 2: Create the command and set its type. var cmd = new SqlCommand("dbo.GetOrdersByCustomer", conn) { CommandType = CommandType.StoredProcedure }; If you forget CommandType, ADO.NET treats the string as ad-hoc SQL text and you get a syntax error. 3: Add parameters by name, with explicit types. cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = customerId; Avoid AddWithValue for anything where the inferred type could differ from the column type — it can force implicit conversions and hurt index usage. 4: Create the adapter and attach the command. var adapter = new SqlDataAdapter(cmd); 5: Fill a DataTable. var table = new DataTable(); adapter.Fill(table); The adapter opens the connection, executes, loads rows, and closes the connection — provided the connection wasn't already open when you called Fill. If it was open, the adapter leaves it open, and you own the close. 6: Dispose the adapter and command (or wrap them in using). The DataTable remains usable with no live connection. 7: Bind or process the table — grid binding, LINQ-to-DataTable, serialization to JSON for a cache file, whatever the UI needs.
Success check: table.Rows.Count matches what you expect, table.Columns shows the procedure's output columns, and conn.State is Closed after the fill if you never opened it yourself. Failure signs: zero rows when you know data exists (wrong parameter value), a SqlException about permission (grant issue), or a timeout (long-running procedure or a lock — check with the DBA before raising the timeout blindly).
If your procedure has output parameters, add them with ParameterDirection.Output before calling Fill, and read cmd.Parameters["@Total"].Value after. Note that output parameters are populated when execution completes, so you need the command object alive after the fill — don't dispose it inside a using block that ends before you read the value.
If it returns multiple result sets, use a DataSet instead of a DataTable and call adapter.Fill(dataSet) with table mappings, or read sequentially with NextResult(). A DataSet with two tables is the disconnected-friendly way to carry related parent/child results around; DataRelation objects can wire the foreign-key relationship in memory.
Handling Updates and Concurrency in the Disconnected Model
Filling is the easy half. Pushing edits back is where disconnected architecture shows its teeth, because between fill and update another user may have changed the row.
The DataAdapter model solves this with the three write commands (InsertCommand, UpdateCommand, DeleteCommand) plus optionally a SelectCommand used for refresh. Each command has a WHERE clause you control — typically matching the primary key plus the original values of the columns you care about, which gives you optimistic concurrency. Generate them with SqlCommandBuilder if the procedure result maps cleanly to a single table, but be aware the builder produces ad-hoc SQL, not procedure calls, so if your policy is "all writes go through procedures," you'll write the commands by hand or skip the adapter's update path entirely.
That second option is common in practice: use the adapter only for reads, and route each changed row through a dedicated INSERT/UPDATE/DELETE procedure inside a transaction on the server. The procedure itself does the concurrency check — UPDATE ... WHERE Id = @Id AND RowVersion = @OriginalRowVersion — and returns a row count; if it's zero, the client knows the row changed and can refetch. That keeps business rules in the database where they belong and keeps the client dumb, which is usually the right trade in a disconnected design.
A practical middle ground for batch saves: pass the changed rows as a table-valued parameter to a single procedure that applies them set-based, inside one transaction, and returns a result set of conflicts. That turns N round trips into one and gives you a clean conflict report. It requires a user-defined table type in the database, so it's a schema change — worth it when the save path is hot.
Both approaches share one rule: never update by primary key alone unless last-write-wins is genuinely acceptable for that table. In disconnected apps, silent overwrites are the most common data-integrity bug, and they're invisible until someone asks why their edit vanished.
The Service-Layer Pattern: Procedures Behind an API
When the "disconnected" client is a web or mobile app, the procedure call belongs on the server, and the client never sees SQL. The API endpoint opens a connection (usually pooled and short-lived), calls the procedure, and maps results.
A minimal shape:
1: The endpoint validates the request and builds a parameter object — never concatenate values into SQL, and never accept a procedure name from the client. 2: Open a connection from the pool, create a SqlCommand with CommandType.StoredProcedure, add typed parameters. 3: Use ExecuteReader for result sets, ExecuteScalar for a single value, or ExecuteNonQuery for writes. 4: Map rows to DTOs inside the using block; the DTOs survive after the connection returns to the pool. 5: Return the DTO as JSON. The client now holds "disconnected" data in the sense that matters: plain objects with no database attachment.
Two conditions matter here. First, connection pooling makes the open/close cheap — a closed SqlConnection usually returns to the pool rather than tearing down TCP, so opening per request is correct, not wasteful. Second, result sets should be small; if a procedure returns 200,000 rows for a mobile client, the problem is the contract, not the architecture. Add paging parameters to the procedure or wrap it.
This pattern also fixes a security problem the direct-client approach creates. If a desktop app connects straight to SQL Server, every user needs database credentials, and those credentials can be extracted from the client. A service layer means only the service holds them.
Fully Offline Clients: Queue Now, Call Later
When the client genuinely has no path to the database or API, you cannot call the procedure at the moment the user acts. What you can do is record the intent and replay it.
The workable sequence:
1: Define an operation record — procedure name (from a fixed allowlist), parameter values, a client-generated idempotency key, a timestamp, and a state field (pending/sent/confirmed/failed). 2: Persist it locally in the client's own store — SQLite, IndexedDB, a local file — inside the same local transaction as the user's other changes, so the queue and the local state stay consistent. 3: Apply the change optimistically to the local cache so the UI responds immediately. 4: On reconnect, send queued operations in order to the API, which calls the procedure and returns success or a conflict. 5: Reconcile: mark confirmed operations done, surface conflicts to the user, and refetch canonical state for affected entities.
The hard part is step 4's ordering and idempotency. If the connection drops after the server commits but before the client gets the response, the client will retry — and the procedure runs twice unless the idempotency key is enforced. The server-side fix is a small table keyed on that client key, checked and inserted in the same transaction as the procedure call. Without it, you get duplicate orders, double-posted payments, and double-decremented inventory, all of which are painful to unpick after the fact.
Server-assigned identity is the other trap. A procedure that returns a new IDENTITY value can't give it to the client at queue time. Either the client generates GUIDs, or the procedure accepts a client-supplied key and treats it as the natural identifier. Pick one before you build the queue, not after.
Choosing Between the Patterns
| Situation | Sensible pattern | Why |
|---|---|---|
| Desktop app, LAN, short bursts of connectivity | DataAdapter + DataTable, procedure for read and write | Fewest moving parts; connection is brief but real |
| Web or mobile client | API endpoint wrapping SqlCommand | No DB credentials on the client; pooled connections |
| Client with no network for hours | Local queue + idempotent replay via API | The call happens later; correctness depends on dedupe |
| Large or multi-result procedures | DataSet with relations, or service-layer DTOs | Keeps related results in one round trip |
| Batch saves of many edited rows | Table-valued parameter to one procedure | One transaction, one round trip, clean conflict report |
There's no universally "better" option here; the deciding factor is whether the client can reach the database or an API at the moment of the action, and whether last-write-wins is acceptable for the affected tables.
Common Failures and How to Tell Them Apart
"Could not find stored procedure." Usually a schema prefix or database context problem — the procedure exists in dbo but the connection's default schema differs, or you're pointed at the wrong database. Check the actual database name in the connection string.
"Procedure or function has too many arguments specified." You added a parameter the procedure doesn't declare, often from a copy-paste. List the parameters from the procedure definition and compare.
"Expects parameter '@X', which was not supplied." The reverse: a missing required parameter, or a value that arrived as null from application code and was never assigned.
Zero rows with no error. Parameter value mismatch (wrong ID, wrong date boundary), or the procedure has internal logic that filters everything out. Run the same parameters in SSMS with the same user to isolate whether it's the call or the data.
Fill succeeds but the grid shows the wrong columns. The procedure's result set changed, or a DataSet table mapping pointed at the wrong table index. Bind by column name, not ordinal.
Update affects zero rows. Optimistic concurrency is working as designed — the original values no longer match. Refetch and let the user reapply, rather than forcing the update.
Intermittent timeouts. Pool exhaustion (connections not disposed) or lock contention. using blocks fix the first; the second needs the DBA, because raising the command timeout just moves the symptom.
Reversible checks first: run the procedure manually with the client's credentials, confirm the connection string's database, and confirm the parameter values by logging them (redacting anything sensitive) at the call site before you touch the procedure's logic.
Limits Worth Knowing Before You Commit
The disconnected model buys scalability and UI responsiveness at the cost of freshness and write complexity. Reads see a snapshot as of the fill; if the procedure is long-running, that snapshot may already be stale by the time the user acts on it. Writes need concurrency handling you'd otherwise get from an open transaction. And every extra layer — adapter, service, queue — is another place where parameters can be dropped or mistyped.
There's also an engine-level caveat: not every database provider supports every pattern identically. DataAdapter-style fill is native to the ADO.NET family; providers for other engines offer equivalents but with different class names and occasionally different behavior around output parameters and multiple result sets. If you're porting code between providers, re-test the parameter direction handling specifically — that's where behavior diverges most often.
For teams maintaining older code, one more practical note: System.Data.SqlClient still works and still appears in legacy projects, but new development should use Microsoft.Data.SqlClient, which is where fixes and current SQL Server feature support land. The call pattern is identical; the namespace is not.