title: Having a c# code which doesn't close SQL Connection correctly (probably)
body: <p>I am facing an issue where a connection to our SQL Server is not closed properly. I can watch the open connections (sleeping) using sp_who2 or sp_who. I do some WEB Calls against the server and can see the number of connections increasing. At a specific number of connections I do run into a Timeout. 
  The Website I call only has the following code (obfuscated) which opens the connection to the SQL Server:</p>
  
  <pre><code>    private string getsomedetails(string Name, string applicationConnectionString)
  {
    string empty = string.Empty;
    SqlCommand sqlCommand = new SqlCommand();
    sqlCommand.Connection = new SqlConnection(applicationConnectionString);
    sqlCommand.CommandText = "SELECT xx FROM dbo.xxx WHERE Name = @xyz";
    sqlCommand.Parameters.AddWithValue("@xyz", (object) Name);
    sqlCommand.Connection.Open();
    return sqlCommand.ExecuteScalar().ToString();
      }
  </code></pre>
  
  <p>I understood that a connection is getting closed when it's in a block as above. But what happens for exceptions? </p>
  
  <p>My connection string looks like:</p>
  
  <pre><code>      &lt;connectionStrings&gt;
  &lt;add name="AssetConnectionString"
       providerName="System.Data.SqlClient"
       connectionString= "server=SERVERNAME; 
                        database=DBNAME; 
                        uid=USERNAME; 
                        pwd=PASSWORD;
                        application name=APPNAME"
     /&gt;
  </code></pre>
  
  <p></p>
  
  <p>My workaround right now it to recycle the app pool in IIS. After that the API will respond as usual.</p>
  
  <p>Some Details:
  Microsoft SQL Server 2014 (SP3-CU4) (KB4500181)
  IIS Version 6.2</p>
  
  <p>My guess is that the code has a leak, any help is upvoted!</p>