0

I got several applications run onto the one machine, also with an MSSQL server on that machine.

Applications are various typed, like WPF, WCF Service, MVC App and so on. All of them accessing the only database, which is located on the sql server. The access mode is the simple LinQ-to-SQL class calls.

In each database concact I make some queries, some checks and some db-writes.

My question is: Can I be sure that calls inside those transaction scopes are not running at the same time (are thread and process safe) by using simple TransactionScope instance?

AgentFire
  • 8,944
  • 8
  • 43
  • 90

1 Answers1

0

Using a transaction scope will obviously make a particular connection transactional. The use of transaction scopes in itself doesn't stop two different processes on a machine doing the same thing at once. It does ensure that all actions performed are either committed or rolled back. The view of data each process sees depends on the isolation level, which by default is serializable, which can easily lead to deadlocks. A more practical isolation level is read comitted, preferably with snapshot isolation as this further reduces deadlocks and waits times.

If you want to ensure only one instance of application is doing something, you can use a mutex or use a database lock that all different processes will attempt to acquire and if necessary wait for.

Xhalent
  • 3,914
  • 22
  • 21
  • I want to ensure that only one applications makes the action "1. check if there is no rows in the table. 2. if so, create one" to be allowed to run in teh way that only 1 row will be created. – AgentFire Jul 11 '12 at 12:12
  • This is a data constraint, and could probably best implemented using an insert trigger. – Xhalent Jul 11 '12 at 22:48