我想弄清楚爲什麼我打開SQL客戶端中的SHOWPLAN
功能時出現「無效光標狀態」錯誤。SQL Server:SHOWPLAN打開時無效的光標狀態
我運行的代碼如下:
SET SHOWPLAN_XML ON;
Select *
From Sys.Objects
SET SHOWPLAN_XML OFF;
This is the error I get when I run this
任何幫助,將不勝感激
我想弄清楚爲什麼我打開SQL客戶端中的SHOWPLAN
功能時出現「無效光標狀態」錯誤。SQL Server:SHOWPLAN打開時無效的光標狀態
我運行的代碼如下:
SET SHOWPLAN_XML ON;
Select *
From Sys.Objects
SET SHOWPLAN_XML OFF;
This is the error I get when I run this
任何幫助,將不勝感激
這應該可以解決您的錯誤。
SET SHOWPLAN_XML ON;
GO
Select * From Sys.Objects
GO
SET SHOWPLAN_XML OFF;
GO
看來你有一個光標,它保持打開狀態。你需要記住DEALLOCATE遊標(其代碼不是你問題的一部分)
DEALLOCATE {{[GLOBAL] cursor_name} @cursor_variable_name}
由於未提供打開的遊標代碼,因此無法告訴您要使用的參數。
我相信這將有助於close all cursors:
-- Declare a cursor variable to hold the cursor output variable
-- from sp_cursor_list.
DECLARE @Report CURSOR;
-- Execute sp_cursor_list into the cursor variable.
EXEC master.dbo.sp_cursor_list @cursor_return = @Report OUTPUT,
@cursor_scope = 2;
-- Fetch all the rows from the sp_cursor_list output cursor.
FETCH NEXT from @Report;
WHILE (@@FETCH_STATUS <> -1)
BEGIN
FETCH NEXT from @Report;
END
-- Close and deallocate the cursor from sp_cursor_list.
CLOSE @Report;
DEALLOCATE @Report;
GO
最重要的是你有其他錯誤。
Msg 1067,Level 15,State 1,Line 0 SET SHOWPLAN語句必須是批處理中的唯一語句 。
由於錯誤提示,您需要將其分成不同的批次。 SET SHOWPLAN必須單獨在批處理中。有需要自己的一批
幾個命令試試這個:
SET SHOWPLAN_XML ON;
GO
SELECT * FROM Sys.Objects;
GO
SET SHOWPLAN_XML OFF;
GO
如果你把每個命令後'GO',創建3個獨立的批次,你得到同樣的錯誤? – scsimon