开发者

ADODB.Recordset error '800a0e78 Operation is not allowed when the object is closed: stored proc against temp table requiring SET NOCOUNT ON

开发者 https://www.devze.com 2023-03-24 17:49 出处:网络
I\'m exploring full text index searching using SQL Server 2008 and encounter two sets of errors. It stems from aa stored procedure I call with VBScript which generates would generate search hit list

I'm exploring full text index searching using SQL Server 2008 and encounter two sets of errors.

It stems from a a stored procedure I call with VBScript which generates would generate search hit list recordset. The stored procedure runs fine in SQL Server Management studio and basically generates a search hit list. Arguments are keyword, and style for highlighting.

Initially error:

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

at the If not recordset.EOF line in the to ASP code. Then a bit of reading and searching pointed having SET NOCOUNT ON; especially when referencing temporary tables (KB235340).

However when I specify SET NOCOUNT ON I get the error listed in "error two". NB regarding permissions I have EXECUTE permission assigned to the account running the stored procedure to highlight the search hits.

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

Error Two occurs when add the SET NOCOUNT ON.

ASP Code: Line causing the error is highlighted

    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

Stored Procedure:

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;


The sys.dm views you use require elevated permissions

  • sys.dm_fts_parser = sysadmin
  • sys.dm_fts_index_keywords_by_document = CREATE FULLTEXT CATALOG

As you mentioned, you are using 2 different sets of credentials.

You are sysadmin in SSMS and plain user from vb script.

You can try "EXECUTE AS OWNER" in the stored procedure. Or try wrapping sys.dm_fts_parser in a view in master (also with EXECUTE AS OWNER)

0

精彩评论

暂无评论...
验证码 换一张
取 消