Hi there everybody.
I've posted in "Getting started with SQL Server" because I think this could be quite a "basic" problem, and I also hope to get some general hints on how to accomplish this sort of task.
Let's say I've got many xml files containig various data. I must read these files in the shortest time possible and then insert data in several Tables on an Sql Server Database.
It's a Sql Server 2008 R2 DB, commercial version.
The Application is made in Visual Studio .NET and each xml file import task ( and so INSERT-in-DB operation ) runs on its own thread.
The problem is simple : sometimes it reults in a "Deadlock" error : Two or more importation tasks are locking resources each other, so Sql Server decides to kill some of them, and some of the xml files aren't imported in DB correctly.
By now my questions are general, and I don't explain here the whole story about the code I use on the application side to read the xml, manage the threads and then insert in the database.
Question 1 :
After several tests on different machines I see that this deadlock problem happens only on fast computers. My idea is that on a quad-core workstation threads are exectuted much more quickly and concurrent operations tend to happen really at the same time, whether
on a slower pc this happens really less frequently ( or never ).
Do you think this can be a good answer ?
Question 2 :
I'm not so expert in Sql Server, but I've always known that this should be one of the main good points of a "Database Server" to manage safely concurrent connections and operations. I think two threads, each one going to INSERT data in the
database, can be seen as two users. If one user locks a table on insert ( and so locks some related tables ) the server should put the second one in a "wait" state and then let him pass, or am I wrong ? Then I don't understand why one of these threads
gets killed in a way that seems instantly...
Queston 3 :
For those who have faced similar problems, running multiple INSERT operations on more threads in .NET : what could be a good and safe way to work ?
Deadlock problems should be solved mainly on the application side or mainly on database side ? Maybe there are particular settings I could use on the Sql Server instance that could lower significantly the odds of deadlock errors...
Many Thanks to everybody able to help.