The part of my program that I am writing is running some T-SQL code. The program will run in a loop until I stop it. When it passes for the first time, there are no problems. When it runs a second time, I get an error when it tries to run T-SQL code. It says that one of the temporary tables that the code creates already exists in the database. The code before it tries to insert records into the temp table disables the temporary table. I do not know if I configured it correctly in the T-SQL code or just failed to run the T-SQL code that deletes the table if it exists. I also tried resetting the table in C # code, here is what I tried:
cn.Open();
string cmdText = @"BEGIN TRANSACTION; DROP TABLE IF EXISTS
SqlCommand command = new SqlCommand(cmdText, cn);
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
cn.Close();
and here an error message appears:
There is already an object named '#temp850' in the database.
Can anyone help?