title: Handles SQL Exception from Entity Framework
body: <p>In my sql stored procedure, i do some insertion and updating which in some scenarios throws Primary Key or unique key violation.</p>
  
  <p>When I try to execute this procedure from ADO.net, .net application also throws that exception and let me know that something wrong had happen.</p>
  
  <p>But when I try to execute this procedure from EF, it just executes. Neither it show anything nor update anything.</p>
  
  <p>How should I handle or notify user that something wrong had happen?</p>
  
  <p>Ado.Net code is </p>
  
  <pre><code> SqlConnection sqlConnection = new SqlConnection(@"data source=database01; database=test; user id=test; password=test;");
          SqlCommand cmd = new SqlCommand("[uspUpdateTest]", sqlConnection);
          cmd.CommandType = System.Data.CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("RunID", RunID);
          cmd.Parameters.AddWithValue("RunCode", RunCode);
          sqlConnection.Open();
          var str = cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>Entity Framework Code is</p>
  
  <pre><code> TestEntities context = new TestEntities();
          var str=context.UpdateRun(RunID, RunCode);
  </code></pre>