Incorrect syntax near @ [parameter name] when using parameterized Alter Database command
I am trying to drop a SQL Server database using the following code:
SqlCommand command = new SqlCommand("USE MASTER; ALTER DATABASE @database SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE @Database", connection);
command.Parameters.AddWithValue("@database", TestingEnvironment.DatabaseName);
command.ExecuteNonQuery();
When I execute it, I get an error:
Incorrect syntax near '@database'. Incorrect syntax near the 'c' keyword. If this statement is a generic table expression or xmlnamespaces, the previous expression must end with a semicolon. Incorrect syntax next to "IMMEDIATE".
What am I doing wrong?
0
source to share