Opening SQL connection more than once at the same time

  • Thread starter Thread starter George Waters
  • Start date Start date
G

George Waters

Guest
Hi,

I have two winforms that open at the same time, each one when loading, creates a new instance of the data layer, both try to get some data from SQL Server 2017, but I always get an error:

There is already an open DataReader associated with this Command which must be closed first

I tried using MultipleActiveResultSets=True in my connection string but no luck, now I get:

Operation is not valid, connection has been terminated

System.Data.ProviderBase.DbConnectionClosed.CreateReferenceCollection()
System.Data.ProviderBase.DbConnectionInternal.AddWeakReference(Object value, Int32 tag)
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
GlobalDataLayer.DxGLOBALLoadTableSQLDataAdapter(String SqlStr) D:\..........\GlobalDataLayerMSSQL.vb:línea 49


So, how can I use my connection to accept to queries at the same time?

Regards



G.Waters

Continue reading...
 
Back
Top