title: Database.ExecuteSqlCommand() Hanging On Execution of Stored Procedure
body: <p>I am working with a database that I do not have much control over. I am trying to execute a stored procedure using the Database.ExecuteSqlCommand method in a C# Web API call. I have been able to successfully use this method on other stored procedures with no issue. When I try to execute this particular stored procedure, however, the application freezes. I have it in a try catch and it doesn't throw any exceptions. It will just stay in this state indefinitely. I have to go into SSMS and kill the process associated to the call. When I kill the process, the Web API continues. If I do the same EXEC command in SSMS, it works just fine returning a single row set of RETURN_VALUE = 0. I added this RETURN_VALUE = 0 manually at the end of the procedure thinking this might have been part of the issue.</p>
  
  <p>The C# code is:</p>
  
  <pre><code>try
  {
      entities.Database.ExecuteSqlCommand("EXEC [dbo].[SPCHANGEORDER]");
      return Ok();
  }
  catch (Exception e)
  {
      Console.WriteLine(e.ToString());
      return Content(HttpStatusCode.BadRequest, "SQL Server Exception");
  }
  </code></pre>
  
  <p>The stored procedure does call some other stored procedures as well as some inserts, updates, and deletes. I know one of the nested stored procedures does several EXEC xp_cmdshell commands as well. I know this isn't a lot to go off of, but I hope someone can help me with a path to at least find the error. Thanks!</p>
  
  <p><strong>EDIT</strong>
  I used SQL Server Profiler and found where it was being executed. I copy/pasted the sets into an SSMS query window, and was still successfully able to execute the stored proc.</p>
  
  <p>Profiler Window</p>
  
  <p><a href="https://i.stack.imgur.com/RQTpC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RQTpC.png" alt="Profiler Window"></a></p>
  
  <p>SSMS Query</p>
  
  <p><a href="https://i.stack.imgur.com/H88eZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H88eZ.png" alt="SSMS Query"></a></p>