title: "deadlocked on lock | communication buffer resources" exception in C# / SQLSERVER
body: <p>I have a c# program working with a SQL Server database running on different client PCs. 
  Now, I am getting this exception which [if not catched] closes my application:</p>
  
  <blockquote>
    <p>Transaction (Process ID ...) was deadlocked on lock | communication
    buffer resources with another process and has been chosen as the
    deadlock victim. Rerun the transaction.</p>
  </blockquote>
  
  <p>and the stack trace shows that the exception happens here:</p>
  
  <blockquote>
    <p>at Gui.DB.sqlServerWrapper.MarkAsNonFreshSample(String barcode, Int32 devID)</p>
  </blockquote>
  
  <p>Where the mentioned method is this:</p>
  
  <pre><code>        public void MarkAsNonFreshSample(string barcode, int devID)
          {
              mux.WaitOne();
              var sql = "DELETE FROM results WHERE barcode=@barcode AND devID=@devID";
              var command = new SqlCommand(sql, conn);
              command.Parameters.AddWithValue("barcode", barcode);
              command.Parameters.AddWithValue("devID", devID);
              command.ExecuteNonQuery();
              mux.ReleaseMutex();
          }
  </code></pre>
  
  <p>I am using the "mux" mutex to exclusive access to the sql connection "conn" because my program has multiple threads.</p>
  
  <p>I am not using a complex query or a long transaction (and I guess this short query is one transaction which should not cause a deadlock. am I wrong?). </p>
  
  <p>Where is the problem and how I should fix it? </p>