Skip to content

Settings.CommandTimeout

Simon Hughes edited this page Sep 10, 2026 · 3 revisions

The setting for when reading your schema is slow or appears to hang.

Type int (seconds)
Default 600
Databases All
In Database.tt? Yes

Settings.CommandTimeout

How long the efrpg tool waits for each schema query before giving up. 0 waits indefinitely.

Ten minutes sounds generous and occasionally is not. Reading a schema is a lot of queries against system tables, and on a large database with stale statistics some of them are slow - see below.

Settings.CommandTimeout = 1200; // 20 minutes
Settings.CommandTimeout = 0;    // No limit

Raising it treats the symptom. If you need more than ten minutes, something is wrong, and the two fixes below are worth trying first. Use 0 only while diagnosing - a template that hangs forever is worse than one that fails.

This is the design-time timeout. It has nothing to do with the timeout your application uses at run time, which you set on the DbContext.

What to try first, in order

1. Turn off stored procedures. On SQL Server, discovering what a procedure returns means executing it under SET FMTONLY ON, once per procedure. On a database with hundreds of procedures this is almost always the entire runtime:

FilterSettings.IncludeStoredProcedures      = false;
FilterSettings.IncludeTableValuedFunctions  = false;
FilterSettings.IncludeScalarValuedFunctions = false;

2. Update the statistics on the system tables. A well-documented SQL Server problem with a fix that takes seconds - see Speed up Reverse generating.

3. Filter down to the tables you need. Fewer tables is less to read, and a DbContext with 40 entities also builds its model faster at run time than one with 900. See Filtering.

4. Only then raise the timeout.

Gotchas

CommandTimeout is per query, not for the whole run. A generation that takes twenty minutes across two hundred queries never trips a ten-minute timeout.

A timeout surfaces as a partial result, not a crash. Each read is wrapped, so a failure is recorded as an error in the payload and the tool exits with code 2. You get generated code missing whatever failed to read, with the error as a comment - which is easy to miss.

It does not affect the generated code. It is about the design-time read.

See also

Clone this wiki locally