【发布时间】:2013-05-13 18:48:57
【问题描述】:
这是我的存储过程,当我从我的经典 ASP 代码中调用它时,我收到了错误:
对象关闭时不允许操作。
当我尝试进行记录计数时。
有人知道这里出了什么问题吗?
我正在尝试返回表格@t。
谢谢。
USE [Hires_new]
GO
/****** Object: StoredProcedure [dbo].[sp_selectNewHireWorkPeriodsSQL] Script Date: 05/13/2013 14:04:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE [dbo].[sp_selectNewHireWorkPeriodsSQL]
-- Add the parameters for the stored procedure here
AS
declare @t table (HireID int, StartDate datetime, EndDate datetime, date_initiated datetime, date_closed datetime, firmName nvarchar(100), InquiryID int)
DECLARE @acc INT
SET @acc = 1
DECLARE @max INT
select @max = max(HireID) from NewHire
WHILE (@acc <= @max)
BEGIN
IF (@acc in (select HireID from NewHire))
BEGIN
insert into @t
select HireID, StartDate, EndDate, date_initiated, date_closed, firmName, Inquiries.InquiryID
from WorkPeriod, Firms, Inquiries
where HireID = @acc and WorkPeriod.FirmID = Firms.FirmID and WorkPeriod.InquiryID = Inquiries.InquiryID
order by HireID,StartDate DESC
END
set @acc = @acc + 1
END
select * from @t
Asp经典代码
selectNewHireWorkPeriodsSQL = "EXEC sp_selectNewHireWorkPeriodsSQL"
Set rsNewHireWorkPeriods = Server.CreateObject("ADODB.Recordset")
rsNewHireWorkPeriods.Open selectNewHireWorkPeriodsSQL,ConnectionString,adOpenStatic
NumOfNewHireWorkPeriods = rsNewHireWorkPeriods.RecordCount
response.write(NumOfNewHireWorkPeriods)
【问题讨论】:
-
我的意思是微软的 sql server。
-
由于错误显然出在调用代码中 - 您需要向我们展示代码调用此存储过程 ....
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本没有前缀! -
好的,我发布了。当我尝试进行记录计数时出现错误。
-
作为另一个旁注,这段代码中似乎不需要循环:您可以通过在
NewHire上添加一个连接将整个事情编写为单个SELECT语句。最好是write your joins explicitly。