You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider adding FillAsync and async APIs on data adapters #22109
api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.DataenhancementProduct code improvement that does NOT require public API changes/additions
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.
Reacted by POPisms, Tim Cohn, NicoBazan1, Dai, Stuart Stein, Tomasz, Denis Perevozchikov, Marco Antonio Regueira, kronic, David Fahlander and 77 more
Reacted by Evgeniy Alexandrov, RabbitFH, Gustavo Mauricio de Barros, Lucio Pelinson, Peter Becker, Boris Drajer and Stefan Greve
@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.
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:
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.
Is the main goal of using async in this case mainly achieving better scalability on the server or more responsiveness on the client?
What other API that perform I/O does Fill use, that would need to become async in order for FillAsync to avoid every blocking?
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.
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
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.
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.
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?
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.
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>publicstaticTask<int>FillAsync(thisDbDataAdapteradapter,DataTabledataTable,CancellationTokencancellationToken=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>publicstaticTask<int>FillAsync(thisDbDataAdapteradapter,DataSetdataSet,CancellationTokencancellationToken=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>publicstaticTask<int>FillAsync(thisDbDataAdapteradapter,DataSetdataSet,stringsrcTable,CancellationTokencancellationToken=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.
________________________________
From: Tauheedul ***@***.***>
Sent: Saturday, June 14, 2025 6:25:20 AM
To: dotnet/runtime ***@***.***>
Cc: Christine Boersen ***@***.***>; Mention ***@***.***>
Subject: Re: [dotnet/runtime] Consider adding FillAsync and async APIs on data adapters (#22109)
[https://avatars.githubusercontent.com/u/9335220?s=20&v=4]tauheedul left a comment (dotnet/runtime#22109)<#22109 (comment)>
Copied from prior thread. Update the SqlDataAdapter.FillAsync to support 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);
—
Reply to this email directly, view it on GitHub<#22109 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADIK7XOQF7DQXPGICSJJT3L3DP2BBAVCNFSM6AAAAABS4BW26OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZSGU4TOOJVGU>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
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.
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.
api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.DataenhancementProduct code improvement that does NOT require public API changes/additions
Activity
saurabh500 commentedon Jan 30, 2018
Moving to future because of lack of resources
saurabh500 commentedon Jan 30, 2018
Alternatively if someone from the community would like to drive this, the effort would be welcome.
danmoseley commentedon Jan 30, 2018
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
jonreis commentedon Jan 31, 2018
Not sure if this helps, but someone has implemented this.
https://github.com/voloda/AsyncDataAdapter/blob/master/AsyncDataAdapter/DataAdapter.cs
Misiu commentedon Oct 16, 2018
@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.
effyteva commentedon Apr 11, 2019
+1 on this,
Perhaps it about time to take care of it?
Misiu commentedon Apr 11, 2019
@danmosemsft @saurabh500 any updates on this?
brendanalexdr commentedon Apr 14, 2019
+1
danmoseley commentedon Apr 14, 2019
@saurabh500?
danmoseley commentedon Apr 14, 2019
@divega
divega commentedon Apr 14, 2019
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:
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.
Is the main goal of using async in this case mainly achieving better scalability on the server or more responsiveness on the client?
What other API that perform I/O does Fill use, that would need to become async in order for FillAsync to avoid every blocking?
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.
divega commentedon Apr 14, 2019
cc @roji @ajcvickers
[-]SqlDataAdapter needs FillAsync to fully support the async pattern.[/-][+]Consider adding FillAsync and async APIs on data adapters[/+]roji commentedon Apr 17, 2019
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.
effyteva commentedon May 13, 2019
Would it help if I publish a PR for that? It seems pretty straightforward.
Effy
101 remaining items
jgilbert2017 commentedon Nov 14, 2023
.net9 pretty please.
Tasin5541 commentedon Mar 7, 2024
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.
roji commentedon Mar 7, 2024
@Tasin5541 and others, I recommend taking a look at Dapper.
Gruski commentedon Apr 28, 2024
Like what? Non ORM direct SQL.
gumbarros commentedon Dec 2, 2024
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?
Added DataExtensions.cs (dotnet/runtime#22109 (comment))
tauheedul commentedon May 22, 2025
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.
tauheedul commentedon Jun 14, 2025
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.
API Usage
ChristineBoersen commentedon Jun 14, 2025
danreg commentedon Dec 18, 2025
roji commentedon Dec 18, 2025
skurth commentedon Feb 11, 2026
roji commentedon Feb 11, 2026
gumbarros commentedon Feb 11, 2026
It’s impressive how Microsoft invests millions in AI, yet
FillAsyncstill 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.
roji commentedon Feb 11, 2026
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.