我正在探索使用SQL Server 2008进行全文索引搜索并遇到两组错误。
它源于我用VBScript调用的存储过程,它生成会生成搜索命中列表记录集。存储过程在SQL Server Management studio中运行良好,基本上生成搜索命中列表。参数是关键字和突出显示的样式。
最初的错误:
错误一: ADODB.Recordset错误'800a0e78关闭对象时不允许操作
在ASP代码的If not recordset.EOF
行。然后,一些读取和搜索指向SET NOCOUNT ON;
,尤其是在引用临时表(KB235340)时。
但是当我指定SET NOCOUNT ON
时,我收到“错误二”中列出的错误。关于权限的NB我已经为运行存储过程的帐户分配了EXECUTE权限,以突出显示搜索命中。
错误二: Microsoft OLE DB Provider for SQL Serve错误'80040e14' 用户无权执行此操作
添加SET NOCOUNT ON
时出现错误二。
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;
答案 0 :(得分:3)
您使用的sys.dm视图需要提升权限
正如您所提到的,您使用的是两套不同的凭据。
您是SSMS中的sysadmin和vb脚本中的普通用户。
您可以在存储过程中尝试“EXECUTE AS OWNER”。或者尝试在master中的视图中包装sys.dm_fts_parser(同时使用EXECUTE AS OWNER)