我尝试使用下面的代码来删除SQL Server数据库:不正确的语法@ [参数名称]当使用参数化alter database命令
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();
当我执行它,我得到的错误:
Incorrect syntax near '@database'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon. Incorrect syntax near 'IMMEDIATE'.
我在做什么错?
没想好,但实际上似乎并不有所作为 – 2008-11-10 17:07:47
你能不能添加PARAM两次那样,用一个中添加PARAM? 可能想尝试使用GO而不是';'... – 2008-11-10 17:14:30