我嘗試使用下面的代碼來刪除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