I have got a multithreaded C2. application where each thread creates some results right into a SQL server 2000 database table. There's merely a straight Place command with no other logic.

My real question is - should i put a lock round the techniques that creates the outcomes towards the database? There's a lock right now however i suspect it's slowing down lower the application by quite a bit.

Thanks!

As Recommended earlier "SqlConnection aren't threadsafe".

Just attempt to Open the bond once throughout the application and MS SQL Server have there internal securing to avoid data lose which means you do not need to to fret.

No you do not need any lock, but you have to produce a new [cde] for every place. The documentation states that instance people of SqlConnection aren't threadsafe.

Edit2: By beeing NOT threadsafe within the situation means that you could not have access to just one SqlConnection shared between several threads. But when each thread have its very own SqlConnection the card inserts are OK. The database itself adheres towards the ACID qualities and therefore concurrent connections attempting to place information is safe and well defined.

Edit: But you ought to be careful when getting rid of strange code if you can't understand why it had been written this way to begin with. It might easily possess some type of side-effect that's non trivial to determine by searching just the database code. But however, when the code was compiled by somebody that copied and pasted some random code found through Google, your best choice is always to rewrite the code anyway.

Since we are speaking about MS SQL Server, I guess they've internal lockings to avoid data corruption. Most contemporary DBMS would do this, otherwise they're going to have large trouble.