G
Guest
Hi all
I am running multiple threads retrieving information from a SQL database, using sqlDataAdapter and DataSet. I regularly (but not constantly) get an exception "There is already an open DataReader associated with this Connection" thrown. Now, I know that the sqlDataAdapter uses DataReader under the hood, and that DataReader does not accept more than one connection open at a time. How might I work around this issue? Having the threads wait for eachother by calling Join() is not an option. I need to run a large number of threads calling this function
I'll add some code to (hopefully) clarify my issue. The function PollSubscriptions is called by multiple threads
private void PollSubscriptions(string devicePIN)
ArrayList subscriptions = new ArrayList()
ArrayList events = new ArrayList()
string subscriptionIDs = ""
XmlDocument XmlDoc = new XmlDocument()
try {
sqlListenerThreadDS.Clear()
sqlListenerThreadDA.SelectCommand.Parameters["@PIN"].Value = devicePIN.ToUpper()
sqlListenerThreadDA.Fill(sqlListenerThreadDS)
foreach (sqlListenerThreadDS.subscriptionsRow subscription in sqlListenerThreadDS.subscriptions)
subscriptions.Add(subscription.subscriptionID.ToString())
sqlSubscriptionsDA.Fill(sqlUserInfoDS)
foreach (string id in subscriptions)
sqlUserInfoDS.subscriptionsRow subscription = sqlUserInfoDS.subscriptions.FindBysubscriptionID(Convert.ToInt32(id))
subscription.lastPoll = System.DateTime.Now.ToUniversalTime()
sqlSubscriptionsDA.Update(sqlUserInfoDS)
catch (Exception ex)
logEntry = "Failed to poll subscriptions for device " + devicePIN.ToUpper() + ": " + ex.Message + "\n" + ex.StackTrace
eventLog.WriteEntry(logEntry, EventLogEntryType.Error)
}
Would anyone know a solution? sqlDataAdapter and DataSet are thread-safe, aren't they
much regard
Eri
(e-mail address removed)
I am running multiple threads retrieving information from a SQL database, using sqlDataAdapter and DataSet. I regularly (but not constantly) get an exception "There is already an open DataReader associated with this Connection" thrown. Now, I know that the sqlDataAdapter uses DataReader under the hood, and that DataReader does not accept more than one connection open at a time. How might I work around this issue? Having the threads wait for eachother by calling Join() is not an option. I need to run a large number of threads calling this function
I'll add some code to (hopefully) clarify my issue. The function PollSubscriptions is called by multiple threads
private void PollSubscriptions(string devicePIN)
ArrayList subscriptions = new ArrayList()
ArrayList events = new ArrayList()
string subscriptionIDs = ""
XmlDocument XmlDoc = new XmlDocument()
try {
sqlListenerThreadDS.Clear()
sqlListenerThreadDA.SelectCommand.Parameters["@PIN"].Value = devicePIN.ToUpper()
sqlListenerThreadDA.Fill(sqlListenerThreadDS)
foreach (sqlListenerThreadDS.subscriptionsRow subscription in sqlListenerThreadDS.subscriptions)
subscriptions.Add(subscription.subscriptionID.ToString())
sqlSubscriptionsDA.Fill(sqlUserInfoDS)
foreach (string id in subscriptions)
sqlUserInfoDS.subscriptionsRow subscription = sqlUserInfoDS.subscriptions.FindBysubscriptionID(Convert.ToInt32(id))
subscription.lastPoll = System.DateTime.Now.ToUniversalTime()
sqlSubscriptionsDA.Update(sqlUserInfoDS)
catch (Exception ex)
logEntry = "Failed to poll subscriptions for device " + devicePIN.ToUpper() + ": " + ex.Message + "\n" + ex.StackTrace
eventLog.WriteEntry(logEntry, EventLogEntryType.Error)
}
Would anyone know a solution? sqlDataAdapter and DataSet are thread-safe, aren't they
much regard
Eri
(e-mail address removed)