Exception: There is already an open DataReader associated with this Command which must be closed first
See original GitHub issue.Net Version 4.6.1 Microsoft.Data.SqlClient 2.01 linq2db 3.1.6
With Oracle: no Problem With SQL-Server: Exception: There is already an open DataReader associated with this Command which must be closed first.
Code:
using (DbContext dbContext = new DbContext(dbProvider))
{
IEnumerable<string> list = dbContext.MENUS_LOG.Select(obj => obj.DATATYPE).Distinct();
foreach(string strItem in list)
{
dbContext.MENUS_LOG.Where(objWhere => objWhere.DATATYPE == strItem)
.Update(dbContext.MENUS_LOG, objWhere => new MENUS_LOG{ DATATYPE = strItem + "X"});
}
}
DataProvider:
Oracle:
m_IDataProvider = new LinqToDB.DataProvider.Oracle.OracleDataProvider(ProviderName.OracleManaged,
LinqToDB.DataProvider.Oracle.OracleVersion.v12);
SQL-Server:
m_IDataProvider = new LinqToDB.DataProvider.SqlServer.SqlServerDataProvider(
ProviderName.SqlServer,
LinqToDB.DataProvider.SqlServer.SqlServerVersion.v2017,
LinqToDB.DataProvider.SqlServer.SqlServerProvider.MicrosoftDataSqlClient);
ConnectionString:
Oracle:
@"USER ID=UserDummy;CONNECTION TIMEOUT=60;PASSWORD=XXXXXX;DATA SOURCE=PKSABNAHME12;STATEMENT CACHE SIZE=0;CONNECTION LIFETIME=0;INCR POOL SIZE=1;STATEMENT CACHE PURGE=True";
SQL-Server:
@"Data Source=MSTEST17\MSTEST17;Initial Catalog=DUMMYDB;Integrated Security=True;Connect Timeout=60;Multiple Active Result Sets=True;Multi Subnet Failover=True;";
Exception:
System.InvalidOperationException
HResult=0x80131509
Message=There is already an open DataReader associated with this Command which must be closed first.
Source=Microsoft.Data.SqlClient
StackTrace:
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
at Microsoft.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
at Microsoft.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery() at LinqToDB.Data.DataConnection.ExecuteNonQuery(IDbCommand command) at LinqToDB.Data.DataConnection.ExecuteNonQuery() at LinqToDB.Data.DataConnection.QueryRunner.ExecuteNonQueryImpl(DataConnection dataConnection, PreparedQuery preparedQuery) at LinqToDB.Data.DataConnection.QueryRunner.ExecuteNonQuery() at LinqToDB.DataContext.QueryRunner.ExecuteNonQuery() at LinqToDB.Linq.QueryRunner.NonQueryQuery(Query query, IDataContext dataContext, Expression expr, Object[] parameters, Object[] preambles) at LinqToDB.Linq.QueryRunner.<>c__DisplayClass32_0.<SetNonQueryQuery>b__0(IDataContext db, Expression expr, Object[] ps, Object[] preambles) at LinqToDB.Linq.ExpressionQuery1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at LinqToDB.LinqExtensions.Update[TSource,TTarget](IQueryable1 source, ITable1 target, Expression`1 setter)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
There is already an open DataReader associated with this ...
There is already an open DataReader associated with this Command which must be closed first. Update: stack trace added:
Read more >Why do I get the error message 'There is already an open ...
This is caused if you are attempting to use the same DataReader more than once in your code without closing the previous Datareader....
Read more >There is already an open DataReader associated with this ...
Close the DataReader & then SqlConnection, if there is an exception is not getting closed. best practices to write this code in try...
Read more >[RESOLVED] There is already an open DataReader ...
InvalidOperationException : There is already an open DataReader associated with this Command which must be closed first. Source Error:
Read more >Script Task: There is already an open DataReader ...
Script Task: There is already an open DataReader associated with this Command which must be closed first. ' A Microsoft platform for building ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is valid error. You cannot issue another query over connection, while previous one is still running.
You can fix it by fetching all data from first query using something like ToList or ToArray
you are a perfect detail i was about to go crazy thank you