title: How to write a stored procedure that use a temp table created from c#
body: <p>I have an application developped in C# that follows this worflow:</p>
  
  <ul>
  <li>Read CSV files</li>
  <li>Create a temp table</li>
  <li>Send the CSV data to the temp table with SqlBulkCopy</li>
  <li>Call a stored procedure to MERGE the temp table in the real table</li>
  <li><p>Delete the temp table</p>
  
  <pre><code>using (var dbConnection = new SqlConnection(_connectionString))
  {
      dbConnection.Open();
  
      using (var cmd = new SqlCommand("CREATE TABLE [#UpdatedData]([Path] [nvarchar](50))", dbConnection))
      {
          cmd.ExecuteNonQuery();
      }
  
      using (var bulkCopy = new SqlBulkCopy(dbConnection))
      {
          bulkCopy.DestinationTableName = "[#UpdatedData]";
  
          bulkCopy.WriteToServer(dt);
      }
  
      using (var cmd = new SqlCommand("usp_MergeData", dbConnection))
      {
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.ExecuteNonQuery();
      }
  
      using (var cmd = new SqlCommand("DROP TABLE [#UpdatedData]", dbConnection))
      {
          cmd.ExecuteNonQuery();
      }
  }
  </code></pre></li>
  </ul>
  
  <p>My problem is I'm creating the temp table in C#, and I can't write the SQL Server stored procedure because it doesn't find the temp table. Is there any workaround?</p>
  
  <p>I'm using localdb for dev and SQL Azure for production.</p>