I'm working on system with a SQL Server database and about 50 clients which are communicating with the database.
In the database, there are two tables, first (orders
) has ~1,3 million rows, second (products
) has around ~3 million rows. Tables are connected by foreign key (one to many relationship).
There is over 50 clients connected to database which are making select and update without knowing each other. In addition I have one client which is receiving new data (orders and products) over TCP and adds it into database (delete old, insert new). This TCP client adds around 50 new orders every minute.
Each of client has their own connection to database. Connection is established for each operation:
- Open
- Operation (Insert, Update, Select, Delete, Transaction)
- Close
At the beginning there was no problem with those multi connections to database, but now, because of lots of clients, sometimes are deadlocks.
To solve this problem, I plan to write a WCF service with Entity Framework which will be able to connect to the database. All clients will do database actions through WCF service.
What is the best practice to handle multi database connections in web service? How should I prevent for deadlock happening?