title: Temp table does not exists even if connection is not closed
body: <p>I have the following code:</p>
  <pre><code>using (var connection = new SqlConnection(constr))
  {
      connection.Open();
  
      var createTempTables = new SqlCommand(&quot;[dbo].[p_CreateTempTable]&quot;, connection)
      {
          CommandType = CommandType.StoredProcedure
      };
  
      createTempTables.Parameters.Add(new SqlParameter(&quot;@Id&quot;, 2));
      createTempTables.ExecuteNonQuery();
  
      var actualCommand = new SqlCommand(&quot;[dbo].[p_Test]&quot;, connection)
      {
          CommandType = CommandType.StoredProcedure
      };
  
      var dt = new DataTable();
  
      dt.Load(actualCommand.ExecuteReader());
  }
  </code></pre>
  <p>Basically, <code>[dbo].[p_CreateTempTable]</code> selects the row matching the ID inut as parameter from a table. Then, <code>[dbo].[p_Test]</code> just selects the temp table. From what I understand, temp tables are supposed to last as long as the connection is not closed, but I always get an exception that says tha my temp table does not exists. Why is this not working ?</p>
  <p>Note: If I instead use a text command that creates the temp table within C# instead, then the program runs with no issues. I however want to avoid doing so, since there will be more validations when creating the temp table and since the application is a WinForms, I would like to avoid recompilation everytime that logics changes.</p>