Skip to content

Add TimeSpan timeouts #1156

Open

Description

@Wraith2

In https://github.com/dotnet/runtime some new apis were approved, dotnet/runtime#14336 , to add TimeSpan timeouts in the BCL where it was appropriate and some of those locations were in SqlClient, SqlClient in the BCL is now in maintenance mode but we can implement those new apis in this library.

Having to use second or millisecond int timeouts has always been a source of bugs and having timeouts be more naturally expressible will feel cleaner for very little cost.

The approved apis that apply to this library were:

namespace System.Data.Sql {
    public sealed class SqlNotificationRequest {
+       public TimeSpan TimeoutTimeSpan { get; set; }
    }
}

namespace System.Data.SqlClient {
    public sealed class SqlBulkCopy {
+       public TimeSpan BulkCopyTimeoutTimeSpan { get; set; }
    }

    public sealed class SqlConnectionStringBuilder {
+       public TimeSpan ConnectTimeoutTimeSpan { get; set; }
+       public TimeSpan LoadBalanceTimeoutTimeSpan { get; set; }
+       public TimeSpan CommandTimeoutTimeSpan { get; set; }
    }

    public sealed class SqlDependency {
+       public SqlDependency(SqlCommand command, string options, TimeSpan timeout);
    }
}

We should also consider adding something to SqlCommand to cover this part:

namespace System.Data {
!   This would need to be a DIM.
    public interface IDbCommand {
+       TimeSpan CommandTimeoutTimeSpan { get; set; }
    }
}

Activity

  1. cheenamalhotra commented on Jul 8, 2021

    @cheenamalhotra
    Member

    Before we consider updating independently maintained APIs, since IDbCommand is not ours I guess SqlCommand would have to wait for dotnet/runtime to release that support. Ideally a change like that should go altogether so there are no more "int" timespans in the driver, otherwise partial breaking changes on the same behavior are not good for user experience.

    So technically, we're going to depend on dotnet/runtime#14336 to be implemented and shipped in a stable release before we can release it. And as there are no serious concerns or demands, it does not seem high priority.

  2. added
    Breaking Change 🔨
    on Jul 8, 2021
  3. Wraith2 commented on Jul 8, 2021

    @Wraith2
    ContributorAuthor

    For SqlCommand we can add our own CommandTimeoutTimeSpan implementation and then make it an override for whatever version of the runtime eventually includes it. For the majority of things we can own the types so we can add the members on whatever timeframe we choose.

    It isn't high priority but external users like me have no visibility of the priority on issues so there's no indication of what's planned for 4.0.0 or beyond.

  4. roji commented on Jul 9, 2021

    @roji
    Member

    Note the API review decision in dotnet/runtime#14336 (comment) which approves adding method overloads, but rejects adding properties and interface DIMs (incidentally I agree). Of course, you can decide to do something else in SqlClient, but those API designers generally know what they're doing - unless you think the ADO.NET timeout properties are somehow different?

    So in general I'm not a big fan... Also, though I completely agree that the current int-based are an API smell, in practice I've seen little actual confusion over the years - users seem to look at the Intellisense docs and get it right.

    Specifically for SqlConnectionStringBuilder, don't forget that you also have the two timeout parameters in the connection string, which already work with seconds. I'm not sure it's a great idea to add a connection string parameter with a TimeSpan string representation (e.g. 00:00:30 for 30 seconds?); and unless you do that, you probably shouldn't add TimeSpan properties to SqlConnectionStringBuilder (since properties on that type are supposed to correspond to string-based parameters).

  5. ErikEJ commented on May 3, 2022

    @ErikEJ
    Contributor

    SqlConnectionStringBuilder.CommandTimeout ?

  6. Wraith2 commented on May 3, 2022

    @Wraith2
    ContributorAuthor

    SqlConnectionStringBuilder.CommandTimeout ?

    Added.

  7. moved this from To triage to Backlog in SqlClient Boardon Dec 16, 2025
  8. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  9. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Feature
    Environment Not applicable (feature/API proposal, not a bug report)
    Area No exact match in the standard area-label list; this is a cross-cutting public API design proposal touching SqlConnectionStringBuilder, SqlBulkCopy, SqlNotificationRequest, SqlDependency, and potentially SqlCommand (already tagged Breaking Change :hammer:)
    Duplicates Potentially related: #1602 (closed — "Use TimeSpan everywhere we use an int for seconds, milliseconds and timeouts")
    Regression Not indicated (this is a forward-looking API proposal, not a regression report)

    Analysis

    This issue proposes adding TimeSpan-based timeout overloads/properties across SqlClient (mirroring API additions approved in dotnet/runtime#14336), replacing the current int second/millisecond timeout parameters. Discussion in the thread notes API-review guidance favoring method overloads over new properties/DIMs, and flags that SqlConnectionStringBuilder timeout properties should stay in sync with connection-string keyword semantics. One follow-up (SqlConnectionStringBuilder.CommandTimeout) was already implemented per a 2022 comment. This is a design-level feature request (not a bug), so no severity/P-level applies; it is a low-urgency, community-requested API ergonomics improvement with no indicated regression risk to existing behavior since it would be additive.

    Next Steps

    • Maintainers should confirm current status: verify whether SqlConnectionStringBuilder.CommandTimeout-related work referenced in the 2022 comment fully closes any part of this issue, or if the broader surface (SqlBulkCopy.BulkCopyTimeoutTimeSpan, SqlNotificationRequest.TimeoutTimeSpan, SqlDependency TimeSpan constructor overload) remains outstanding.
    • Review [API Proposal]: Use TimeSpan everywhere we use an int for seconds, milliseconds and timeouts #1602 for overlapping scope before further design work, to avoid duplicate discussion threads.
    • If proceeding, scope this as an implement-feature workflow item: define the full public API diff (favoring overloads over new properties per the dotnet/runtime API review precedent cited in the thread), update the relevant ref/ reference assemblies, and add tests validating both the new TimeSpan overloads and continued back-compat of the existing int-based members.
    • Given this is a multi-year-old, low-activity feature request without a confirmed active owner, recommend maintainers explicitly re-prioritize or close as won't-fix if no longer aligned with current roadmap, rather than leaving it in indefinite limbo.

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #1156 · copilot · auto · 50.5 AIC · ⌖ 14.1 AIC · ⊞ 11.9K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking Change 🔨

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions