2011-08-03 48 views
4

我在探索使用SQL Server 2008進行全文索引搜索並遇到兩組錯誤。ADODB.Recordset error'800a0e78當對象關閉時不允許操作:存儲proc對臨時表需要SET NOCOUNT ON

它源於我用VBScript調用的存儲過程,它會生成搜索命中列表記錄集。存儲過程在SQL Server Management Studio中運行良好,基本上會生成一個搜索命中列表。參數是關鍵字,用於突出顯示的樣式。

最初錯誤:

Error One: ADODB.Recordset error '800a0e78 Operation is not allowed when the object is closed

在所述If not recordset.EOF線到ASP代碼。然後,一些閱讀和搜索指向SET NOCOUNT ON;,尤其是在引用臨時表時(KB235340)。

但是,當我指定SET NOCOUNT ON時,出現「錯誤二」中列出的錯誤。注意關於權限我有EXECUTE權限分配給運行存儲過程的帳戶來突出搜索命中。

Error Two: Microsoft OLE DB Provider for SQL Serve error '80040e14' The user does not have permission to perform this action

添加SET NOCOUNT ON時發生錯誤2。

ASP代碼:行導致該錯誤被突出顯示

Dim cmd 
    Dim newParameter 
    Dim recordset 
    Dim SearchTerm 
    Dim Style 

    SearchTerm = "" 
    SearchTerm = Request("searchTerm") 
    Style = "background-color:yellow; font-weight:bold" 

    Dim objConnectionMICenter 
    Set objConnectionMICenter = Server.CreateObject("ADODB.Connection") 
    objConnectionMICenter.Open Session("ConnectMICenter") 

    Set cmd = Server.CreateObject("ADODB.Command") 
    Set cmd.ActiveConnection = objConnectionMICenter 

    ' Define the stored procedure's inputs and outputs 
    ' Question marks act as placeholders for each parameter for the 
    ' stored procedure 
    cmd.CommandType = 4 ' adCmdStoredProc 
    cmd.CommandText = "HelpAndCalculationNoteHighlight" 

    '--- Create and append parameter for SearchTerm 
    Set newParameter = cmd.CreateParameter("SearchTerm",203 ,1,100,SearchTerm) 
    cmd.Parameters.Append newParameter 

    '--- Create and append parameter for SearchTerm 
    Set newParameter = cmd.CreateParameter("Style",203 ,1,200,Style) 
    cmd.Parameters.Append newParameter 

    Set recordset = cmd.Execute() 

    **If not recordset.EOF Then** 
     While Not recordset.EOF 
      response.Write "<div>" & recordset.Fields("Snippet") & "</div>" 
      recordset.MoveNext 
     Wend 
    end if 

    Response.Write strPreviewContents 

    Set objConnectionMICenter = Nothing 
    Set newParameter = Nothing 
    Set cmd = Nothing 

    recordset.Close 
    Set recordset = Nothing 

存儲過程:

ALTER PROCEDURE [dbo].[HelpAndCalculationNoteHighlight] 
@SearchTerm nvarchar(100), 
@Style nvarchar(200) 
AS 
BEGIN 
-- SET NOCOUNT ON added to prevent extra result sets from 
-- interfering with SELECT statements. 
SET NOCOUNT ON; 

CREATE TABLE #match_docs 
(
doc_id bigint NOT NULL PRIMARY KEY 
); 

INSERT INTO #match_docs 
(
doc_id 
) 
SELECT DISTINCT 
id 
FROM IntegratedHelpNotes_ChildSectionPage 
WHERE FREETEXT 
(
content, 
@SearchTerm, 
LANGUAGE N'English' 
); 

-- Begin Second Block 
DECLARE @db_id int = DB_ID(), 
@table_id int = OBJECT_ID(N'IntegratedHelpNotes_ChildSectionPage'), 
@column_id int = 
(
SELECT 
column_id 
FROM sys.columns 
WHERE object_id = OBJECT_ID(N'IntegratedHelpNotes_ChildSectionPage') 
AND name = N'content' 
); 

-- Begin Third Block 
SELECT 
    s.id, 
    MIN 
    (
     N'...' + SUBSTRING 
     (
      REPLACE 
       ( 
        c.content, 
        s.Display_Term, 
        N'<span style="' + @Style + '">' + s.Display_Term + '</span>' 
       ), 
      s.Pos - 512, 
      s.Length + 1024 
     ) + N'...' 
    ) AS Snippet 
    FROM 
    (
     SELECT DISTINCT 
      c.id, 
      w.Display_Term, 
      PATINDEX 
       (
        N'%[^a-z]' + w.Display_Term + N'[^a-z]%', 
        c.content 
       ) AS Pos, 
      LEN(w.Display_Term) AS Length 
     FROM sys.dm_fts_index_keywords_by_document 
      (
       @db_id, 
       @table_id 
      ) w 
     INNER JOIN dbo.IntegratedHelpNotes_ChildSectionPage c 
      ON w.document_id = c.id 
      WHERE w.column_id = @column_id 
       AND EXISTS 
        (
         SELECT 1 
         FROM #match_docs m 
         WHERE m.doc_id = w.document_id 
        ) 
       AND EXISTS 
       (
        SELECT 1 
        FROM sys.dm_fts_parser 
         (
          N'FORMSOF(FREETEXT, "' + @SearchTerm + N'")', 
          1033, 
          0, 
          1 
         ) p 
        WHERE p.Display_Term = w.Display_Term 
        ) 
       ) s 
      INNER JOIN dbo.IntegratedHelpNotes_ChildSectionPage c 
      ON s.id = c.id 
      GROUP BY 
      s.id; 
DROP TABLE #match_docs; 
END; 

回答

3

您使用需要提升權限

如上所述,您正在使用2組不同的憑證。

您是SSMS中的系統管理員,也是vb腳本中的普通用戶。

您可以嘗試存儲過程中的「EXECUTE AS OWNER」。或者嘗試在主視圖中包裝sys.dm_fts_parser(也可以使用EXECUTE AS OWNER)

+0

乾杯隊友。經過數小時的挫折之後,非常滿意地獲得解決方案 – Terman

相關問題