我知道这可能是另一个问题的愚蠢,但我真的不知道,我已经搜遍了所有的东西,但它似乎仍然给了我同样的错误;
ADODB.Recordset错误'800a0e78'
关闭对象时不允许操作。
如果有人可以帮助我,我将非常感激,我使用的是经典的ASP,SQL和HTML;
我的经典ASP代码是;
If(Request.Form("submitBtn"))<>""Then
'Initialise the db connection
Set objDBConn = Server.CreateObject("ADODB.Connection")
objDBConn.Open "Provider=sqloledb;Data Source=OLIVERBEELEY;Initial Catalog=HolidayEmployeeBooker;User ID=HBA;Password=HBA;"
'Initialise the command object
Set objDBCommand = Server.CreateObject("ADODB.Command")
objDBCommand.ActiveConnection = objDBConn
objDBCommand.CommandText = "spNewHoliday"
objDBCommand.CommandType = adCmdStoredProc
'Set the parameters
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@StartDate", adDate, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@EndDate", adDate, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@EmployeeID", adVarChar, adParamInput,200)
objDBCommand.Parameters.Append objDBCommand.CreateParameter("@Reason", adVarChar, adParamInput,200)
objDBCommand("@StartDate") = Request.Form("from")
objDBCommand("@EndDate") = Request.Form("to")
objDBCommand("@EmployeeID") = Session("UserID")
objDBCommand("@Reason") = Request.Form("comments")
'Initialise the Recordset
Set objDBRS = Server.CreateObject("ADODB.RecordSet")
'Execute
objDBRS.open objDBCommand,,adOpenForwardOnly
if not objDBRS.EOF then
Session("BookingValid") = objDBRS(0)
end if
if Session("BookingValid") = "ErrorBookingHoliday" then
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Holiday CANNOT be booked."");</SCRIPT>")
end if
if Session("BookingValid") = "ErrorBookingHoliday" then
response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""Holiday has been requested."");</SCRIPT>")
end if
'Close and Destroy Objects - Start*******************************************************
Set objDBCommand=nothing
objDBConn.Close
Set objDBConn=nothing
'Close and Destroy Objects - End*********************************************************
response.redirect("newbooking.asp")
end if
%>
我的存储过程是它的呼叫;
PROCEDURE [dbo].[spNewHoliday]
(
@StartDate DATE,
@EndDate DATE,
@EmployeeID INT,
@Reason NVARCHAR (45)
)
AS
SET NOCOUNT ON
BEGIN
IF NOT EXISTS ( SELECT 1
FROM Holidays
WHERE @StartDate = StartDate
AND @EndDate = EndDate
AND @EmployeeID = EmployeeID)
BEGIN
DECLARE @Validation INT
EXEC spBusinessRuleValidation @StartDate, @EndDate, @EmployeeID, @Validation OUTPUT
IF @Validation = 0
BEGIN
DECLARE @DaysOff AS INT
SELECT @DaysOff = (DATEDIFF(Day,@StartDate,@EndDate) +1)
UPDATE Employees
SET AnnualDaysHolidayAllowance = AnnualDaysHolidayAllowance - @DaysOff
WHERE @EmployeeID = Employees.ID
INSERT INTO Holidays(EmployeeID, StartDate, EndDate, Duration, Status, Reason)
VALUES(@EmployeeID, @StartDate, @EndDate, @DaysOff,'Pending', @Reason)
SELECT Employees.AnnualDaysHolidayAllowance AS Daysleft FROM Employees WHERE @EmployeeID = Employees.ID
END
SET NOCOUNT ON
IF @Validation = 1
BEGIN
SELECT 'ErrorBookingHoliday' AS FailedBooking
END
END
END
该程序正在调用的存储过程是
PROCEDURE [dbo].[spBusinessRuleValidation]
(
@StartDate DATE,
@EndDate DATE,
@EmployeeID INT,
@Validation INT output
)
AS
SET NOCOUNT ON
BEGIN
DECLARE @JobRoleID INT
DECLARE @MaxJobTypeAllowedOff INT
DECLARE @MaxEmployeesAllowedOff INT
DECLARE @DateCount INT
DECLARE @SameJobRoleOff INT
DECLARE @DateCheck DATE
SET @JobRoleID = (SELECT JobRoleID FROM Employees WHERE @EmployeeID = Employees.ID)
SET @MaxJobTypeAllowedOff = (SELECT MaxEmployeesAllowedOff FROM JobRole WHERE @JobRoleID = JobRole.ID)
SET @MaxEmployeesAllowedOff = 20
SET @DateCheck = @StartDate
SET @EndDate = DATEADD(DAY, 1, @EndDate)
SET @Validation = '0'
WHILE (@DateCheck <> @EndDate)
BEGIN
SET @DateCount = (SELECT COUNT (*) FROM Holidays WHERE Holidays.Startdate >= @DateCheck AND Holidays.EndDate <= @EndDate )
IF @DateCount > @MaxEmployeesAllowedOff
BEGIN
SET @Validation = '1'
BREAK
END
SET @SameJobRoleOff = (SELECT COUNT (*) JobRoleID
FROM Employees
RIGHT JOIN Holidays
ON Employees.ID = Holidays.EmployeeID
WHERE Employees.ID = @EmployeeID AND Holidays.Startdate >= @DateCheck AND Holidays.EndDate <= @EndDate AND Holidays.Status <> 'Declined')
IF @SameJobRoleOff > @MaxJobTypeAllowedOff
BEGIN
SET @Validation = '1'
BREAK
END
SET @DateCheck = DATEADD(DAY, 1, @DateCheck)
END
END
我是SQL和ASP的新手(大约3-4个月的经验)并且需要一些帮助来解决这个问题,任何帮助都会受到赞赏,即使它只是与我的错误导致的代码有关!谢谢!哦,这是出错的代码!
if not objDBRS.EOF then
Session("BookingValid") = objDBRS(0)
end if
答案 0 :(得分:0)
我有几个SP在操作结束时返回一行记录集,使用类似
的内容 SELECT @some_symbol some_column_name;
如果我从这些存储过程中省略SET NOCOUNT ON
,那么我的经典ASP adodb记录集就没有正确返回,我得到了&#34;对象已关闭&#34;错误。
如果我在这些存储过程中包含SET NOCOUNT ON
,那么一切正常。
如果我以相同的方式运行一个普通的SQL块而不是存储过程,那也是如此。
就经典ASP而言,我肯定在&#34;为什么要问为什么?&#34;营。我只需完成维护工作。