Skip to content

RelationalDbContextOptionsBuilder.CommandTimeout should accept zero as a valid value #33196

@SteSinger

Description

@SteSinger

We are running into an issue while trying to set an infinite timeout for our dbcontext.
During startup we are configuring our context with UseSqlServer und setting CommandTimeout on the builder.
options.UseSqlServer(connectionString, builder => builder.CommandTimeout(0));

This calls WithCommandTimeout internally and throws an exception for values <= 0.

public virtual RelationalOptionsExtension WithCommandTimeout(int? commandTimeout)
{
if (commandTimeout is <= 0)
{
throw new InvalidOperationException(RelationalStrings.InvalidCommandTimeout(commandTimeout));
}
var clone = Clone();

The documentation lists 0 as a valid value.

Setting the timeout with context.Database.SetCommandTimeout(0) or context.Database.SetCommandTimeout(Timeout.Infinite) works as expected.

Should be a small change. We could create a PR if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions