I have an application developped in C# that follows this worflow:
- Read CSV files
- Create a temp table
- Send the CSV data to the temp table with SqlBulkCopy
- Call a stored procedure to MERGE the temp table in the real table
Delete the temp table
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(); } }
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?
I'm using localdb for dev and SQL Azure for production.