I am using SQL Server 2000 with ASP 3.0
I got a cursor error:
"Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]A cursor with the name '_cursor_courses' already exists. "
My SQL Statement:
DECLARE _cursor_courses CURSOR
FOR
SELECT dplan_aa.course_code
FROM dplan_aa INNER JOIN
course_info ON dplan_aa.course_code = course_info.course_code INNER JOIN department_info ON course_info.department_id = department_info.department_id
WHERE (department_info.department_id = 'LIB')
OPEN _cursor_courses
DECLARE @course_code varchar(50)
FETCH NEXT FROM _cursor_courses into @course_code
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
DECLARE _cursor_learner CURSOR
FOR
SELECT dplan_aa.learner_id
FROM dplan_aa INNER JOIN learner_programs ON dplan_aa.learner_program_id = learner_programs.learner_program_id
WHERE (dplan_aa.assigned_course = 0) AND (dplan_aa.course_code = @course_code)
DECLARE @learner_id char(10)
OPEN _cursor_learner
FETCH NEXT FROM _cursor_learner into @learner_id
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
INSERT INTO tempRemainingCourses
( course_code,
learner_id )
VALUES ( @course_code,
@learner_id)
FETCH NEXT FROM _cursor_learner into @learner_id
END
CLOSE _cursor_learner
DEALLOCATE _cursor_learner
END
FETCH NEXT FROM _cursor_courses into @course_code
END
About 4 out of 10 time I get the error above but 6 out of 10 times everything runs fine.
What could be wrong???
Please help.