Skip to content

Consider adding FillAsync and async APIs on data adapters #22109

Open

Description

@spudcud

Core 2.0 preview 1 now supports SqlDataAdapter and DataTable which is great and the best way to fill a DataSet from a stored procedure is by using SqlDataAdapter.Fill(DataSet). This works perfectly when not used in an async environment. There is currently no way in Core or full .NET to do a FillAsync. Without a FillAsync which would take a single line of code now requires 20 lines of much more complicated code including using SqlDataReader.GetSchemaTable() which is currently broken preview 1. Based on other posts I believe it will be working in Preview 2 but have not seen a definitive on that.

This is not something for 2.0 but is a clear deficiency in truly being able to support a fully async back-end and would be a much needed improvement moving forward.

Activity

  1. saurabh500 commented on Jan 30, 2018

    @saurabh500
    Contributor

    Moving to future because of lack of resources

  2. saurabh500 commented on Jan 30, 2018

    @saurabh500
    Contributor

    Alternatively if someone from the community would like to drive this, the effort would be welcome.

  3. danmoseley commented on Jan 30, 2018

    @danmoseley
    Contributor

    This needs a formal API proposal written up. @spudcud do you want to do this - updating your top post is clearest?
    See https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/api-review-process.md

  4. jonreis commented on Jan 31, 2018

    @jonreis
  5. Misiu commented on Oct 16, 2018

    @Misiu

    @danmosemsft any chance this can be added to Core 3.0?
    I've added package suggested by @jonreis and it looks like it works fine 😄 Ideally this should be added into Core.

  6. effyteva commented on Apr 11, 2019

    @effyteva

    +1 on this,
    Perhaps it about time to take care of it?

  7. Misiu commented on Apr 11, 2019

    @Misiu

    @danmosemsft @saurabh500 any updates on this?

  8. brendanalexdr commented on Apr 14, 2019

    @brendanalexdr

    +1

  9. danmoseley commented on Apr 14, 2019

    @danmoseley
    Contributor
  10. danmoseley commented on Apr 14, 2019

    @danmoseley
    Contributor
  11. divega commented on Apr 14, 2019

    @divega
    Contributor

    Moving to out of System.Data.SqlClient and into System.Data because I believe the methods should be added to the base DbDataAdapter, before any provider implements it.

    I am also keeping this issue in the Future milestone because we need a much better understanding of its impact before we decide to pick it up and implement it in a specific release. For example:

    1. How many modern applications that take advantage of async would start using async APIs on DataSet/DataAdapter if they were available? Why don't they use other more modern data access technologies that already support async? I appreciate that a few people have voted for this issue and have been asking for updates on it. This adds up to a bit of data, but we need more, especially given that there are many other things in the backlog that seem to have much more demand.

    2. Is the main goal of using async in this case mainly achieving better scalability on the server or more responsiveness on the client?

    3. What other API that perform I/O does Fill use, that would need to become async in order for FillAsync to avoid every blocking?

    4. What about the async Update story for DataSet/DataTable?

    On the flip side, If someone from the community wanted to drive this, I believe the API design part, and possibly the implementation of FillAsync on SqlClient, would be relatively simple. The job is mostly to duplicate the code of the sync version into async methods, and also make sure that all potentially blocking calls in the implementation use async APIs as well.

    For the SqlCient implementation of Update, currently batching is internal and synchronous. I suspect it would make sense to leverage the new public batching APIs from https://github.com/dotnet/corefx/issues/35135 once they are in place.

  12. divega commented on Apr 14, 2019

    @divega
    Contributor
  13. changed the title [-]SqlDataAdapter needs FillAsync to fully support the async pattern.[/-] [+]Consider adding FillAsync and async APIs on data adapters[/+] on Apr 14, 2019
  14. roji commented on Apr 17, 2019

    @roji
    Member

    Similar to dotnet/corefx#35012, which adds missing async APIs elsewhere in ADO.NET.

    Adding these APIs in the System.Data base classes is probably easy enough (with them delegating by default to the sync APIs, as usual with ADO.NET), allowing providers to implement later.

  15. effyteva commented on May 13, 2019

    @effyteva

    Similar to dotnet/corefx#35012, which adds missing async APIs elsewhere in ADO.NET.

    Adding these APIs in the System.Data base classes is probably easy enough (with them delegating by default to the sync APIs, as usual with ADO.NET), allowing providers to implement later.

    Would it help if I publish a PR for that? It seems pretty straightforward.

    Effy

  16. 101 remaining items

  17. jgilbert2017 commented on Nov 14, 2023

    @jgilbert2017

    .net9 pretty please.

  18. Tasin5541 commented on Mar 7, 2024

    @Tasin5541

    Definitely need this for cases where EF Core is not good enough for maintaining SLA and have to end up using Stored Procedure with multiple datasets.

  19. roji commented on Mar 7, 2024

    @roji
    Member

    @Tasin5541 and others, I recommend taking a look at Dapper.

  20. Gruski commented on Apr 28, 2024

    @Gruski

    Why don't they use other more modern data access technologies?

    Like what? Non ORM direct SQL.

  21. gumbarros commented on Dec 2, 2024

    @gumbarros

    Sorry for messaging at the thread, it's possible of reviewing this PR again with a API proposal?
    #36746

    This issue seems very critical to me, there is no way to populate a DataTable completely asynchronously or any way to work with dynamic runtime data at EF Core. Any chance for .NET 10?

  22. tauheedul commented on May 22, 2025

    @tauheedul

    The SqlDataAdapter FillAsync() should be updated to include a support for CancellationToken which cancels querying in the database and disconnects from the database after the specified elapsed period especially for large queries while the processing is being done at the database layer in SQL Server or while a DataSet is being populated in the application etc.

    I have an application using SqlDataAdapter with a Fill() command. The issue I have in the instance of the SQL Query returning a large dataset, the database is returning a large volume of records and is continuously querying. Extending the CommandTimeout value didn't exit the query after the period had elapsed. For example, the database was still querying the records for several hours during validation even when the SqlCommand.CommandTimeout value was less.

    Since there is no async functionality with a cancellation token parameter. I am using a tokenRegistration approach before the Fill(), but this is not as reliable.

  23. tauheedul commented on Jun 14, 2025

    @tauheedul

    Copied from prior thread because not relevant to SqlDataAdapter.Fill().

    Add a SqlDataAdapter.FillAsync() that supports CancellationToken parameter that will exit large batches while filling dataset or datatable object.

            /// <summary>
            /// Asynchronously fills a DataTable with data from the source using the SelectCommand.
            /// </summary>
            /// <param name="adapter">The data adapter to use for the fill operation.</param>
            /// <param name="dataTable">The DataTable to fill.</param>
            /// <param name="cancellationToken">A CancellationToken to observe while waiting for the task to complete.</param>
            /// <returns>A task that represents the asynchronous operation. The task result contains the number of rows successfully added to the DataTable.</returns>
            /// <exception cref="OperationCanceledException">The operation was cancelled via the cancellation token.</exception>
            public static Task<int> FillAsync(
                this DbDataAdapter adapter, 
                DataTable dataTable, 
                CancellationToken cancellationToken = default);
    
            /// <summary>
            /// Asynchronously fills a DataSet with data from the source using the SelectCommand.
            /// </summary>
            /// <param name="adapter">The data adapter to use for the fill operation.</param>
            /// <param name="dataSet">The DataSet to fill.</param>
            /// <param name="cancellationToken">A CancellationToken to observe while waiting for the task to complete.</param>
            /// <returns>A task that represents the asynchronous operation. The task result contains the number of rows successfully added to the DataSet.</returns>
            /// <exception cref="OperationCanceledException">The operation was cancelled via the cancellation token.</exception>
            public static Task<int> FillAsync(
                this DbDataAdapter adapter, 
                DataSet dataSet, 
                CancellationToken cancellationToken = default);
    
            /// <summary>
            /// Asynchronously fills a specified table within a DataSet with data from the source using the SelectCommand.
            /// </summary>
            /// <param name="adapter">The data adapter to use for the fill operation.</param>
            /// <param name="dataSet">The DataSet to fill.</param>
            /// <param name="srcTable">The name of the source table to use for table mapping.</param>
            /// <param name="cancellationToken">A CancellationToken to observe while waiting for the task to complete.</param>
            /// <returns>A task that represents the asynchronous operation. The task result contains the number of rows successfully added to the DataSet.</returns>
            /// <exception cref="OperationCanceledException">The operation was cancelled via the cancellation token.</exception>
            public static Task<int> FillAsync(
                this DbDataAdapter adapter, 
                DataSet dataSet, 
                string srcTable, 
                CancellationToken cancellationToken = default);
    
            // Additional overloads could be considered to match paging functionality, etc.
        }
    • Inside the loop, before adding a row to the DataTable, it would check cancellationToken.ThrowIfCancellationRequested() or check cancellationToken.IsCancellationRequested and exit using sqlCommand.Cancel() if the database is querying before returning an exception. This ensures cancellation is respected even during the client-side population phase, which is a major improvement.

    API Usage

    var tokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(1));
    int count = await adapter.FillAsync(table, tokenSource.Token);
  24. ChristineBoersen commented on Jun 14, 2025

    @ChristineBoersen
  25. danreg commented on Dec 18, 2025

    @danreg
  26. roji commented on Dec 18, 2025

    @roji
  27. skurth commented on Feb 11, 2026

    @skurth
  28. roji commented on Feb 11, 2026

    @roji
  29. gumbarros commented on Feb 11, 2026

    @gumbarros

    It’s impressive how Microsoft invests millions in AI, yet FillAsync still doesn't exist. Maybe @Copilot could just implement it, since apparently allocating some developers for it is harder than training large language models.

    That said, apologies for the sarcasm, but this is genuinely a long-standing gap, and it would be great to see it properly addressed, ideally in .NET 11 given how there is no alternative for non-strongly typed data.

  30. roji commented on Feb 11, 2026

    @roji
    Member

    given how there is no alternative for non-strongly typed data

    DbDataReader is the alternative for non-strongly typed data. Unfortunately, resources are limited and not everything can be done; DbDataAdapter is old technology that we generally recommend people move away from.

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

    api-suggestionarea-System.Dataenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions