Note that there are some explanatory texts on larger screens.

plurals
  1. POParallel.Foreach loop creating multiple db connections throws connection errors?
    primarykey
    data
    text
    <p>The 'login failed' error has never resurfaced, curious? However the other connection errors seem to be explained by slamming the server. The randomness with which the errors occur, still a mystery.</p> <blockquote> <p>Login failed. The login is from an untrusted domain and cannot be used with Windows authentication</p> </blockquote> <p>I wanted to get my code running in parallel, so I changed my foreach loop to a parallel foreach loop. It seemed simple enough. Each loop connects to the database, looks up some stuff, performs some logic, adds some stuff, closes the connection. But I get the above error?</p> <p>I'm using my local sql server and entity framework (each loop uses it's own context). Is there some problem with connecting multiple times using the same local login or something? How did I get around this?</p> <p>I have (before trying to covert to a parallel.foreach loop) split my list of objects that I am foreach looping through into four groups (separate csv files) and run four concurrent instances of my program (which ran faster overall than just one, thus the idea for parallel). So it seems connecting to the db shouldn't be a problem?</p> <p>Any ideas?</p> <p><strong>EDIT</strong>: Here's before</p> <pre><code>var gtgGenerator = new CustomGtgGenerator(); var connectionString = ConfigurationManager.ConnectionStrings["BioEntities"].ConnectionString; var allAccessionsFromObs = _GetAccessionListFromDataFiles(collectionId); ForEach(cloneIdAndAccessions in allAccessionsFromObs) DoWork(gtgGenerator, taxonId, organismId, cloneIdAndAccessions, connectionString)); </code></pre> <p>after</p> <pre><code>var gtgGenerator = new CustomGtgGenerator(); var connectionString = ConfigurationManager.ConnectionStrings["BioEntities"].ConnectionString; var allAccessionsFromObs = _GetAccessionListFromDataFiles(collectionId); Parallel.ForEach(allAccessionsFromObs, cloneIdAndAccessions =&gt; DoWork(gtgGenerator, taxonId, organismId, cloneIdAndAccessions, connectionString)); </code></pre> <p>Inside the DoWork I use the BioEntities</p> <pre><code>using (var bioEntities = new BioEntities(connectionString)) {...} </code></pre> <p>It gets curiouser and curiouser...</p> <p>I added some code in my DoWork method:</p> <pre><code>Debug.WriteLine(“Executing “ + itemName + ” as “ + WindowsIdentity.GetCurrent().Name); </code></pre> <p>and it mysteriously started working (quite well/fast actually). But eventually I got the same excepetion (after about an hour). But I was able to trace this..?</p> <pre><code>A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll </code></pre> <p><strong>EDIT2:</strong> Hmm.. I came in to work and fired it up this morning (obsessed with understanding why it would work for a little bit) and it is cruising along working fine (and fast!) so far. Occasional : The thread '' (0x27c8) has exited with code 0 (0x0). The thread '' (0x26b8) has exited with code 0 (0x0).</p> <p>But other than that it hasn't messed up yet? Which, frankly, just worries me more. This is a one-off thing so I may use it (if it works), but what is going on? Could it be NLOG, logging in the multiple threads clogs stuff up and causes timeouts in the sql? I really don't get it. Once it stops working again, I'll try to figure things out. Is there a way to reset the sql server, I'm not sure why it would work for an hour, then mess up, then never work for more than a couple seconds, and now (after a reboot) work (for about 30 minutes so far)? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload