title: SQL Server is executing two Insert queries simultaneously that results in the pulling of same registration no for two patients
body: <p>I am using SQL Server 2008 R2 Express with VS2010 ultimate c#. It's a client server architecture software of registering patients. there are 4 clients where 4 users are registering the patients. When 2 users are registering 2 separate patients and they hit the save button, then I am doing the following steps,</p>
  
  <ol>
  <li>system pulls the next registration no.</li>
  <li>saves the record with a that registration no. into SQL Server table</li>
  <li>again pulls the next registration no. for the next patient</li>
  </ol>
  
  <p>If both users press the save button exactly at the same time, then SQL Server should put them in a queue regardless of the face that both users have hit the save button at the same time, SQL Server should execute the insert command of first patient, then generate next number and second insert command should execute just next to the first. so that the second query can pull the next registration no and then save the record. but it is saving two patient with the same registration no. I have even used <code>BeginTransaction</code>, <code>Commit</code> and <code>Rollback</code> as well but still I am in a fix. Any help will be appreciated.</p>