Wrox Programmer Forums
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2005, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cursor Error

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.



 
Old December 3rd, 2005, 06:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Do you close and deallocate the cursor "_cursor_courses"?

I obviously don't know the full requirements and structure of your database but it seems to me you could do these inserts using standard SQL without resorting to cursors at all.


--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Magnetic Cursor - Target Area Cursor? gcarcass .NET Framework 2.0 1 May 5th, 2008 07:20 AM
Regarding Cursor param99 SQL Server 2000 1 September 8th, 2006 10:03 AM
Regarding Cursor param99 SQL Language 0 September 8th, 2006 03:56 AM
cursor trinnie SQL Server 2000 0 August 6th, 2006 09:55 PM
Microsoft Cursor Engine error '80004005' gmr1970 Classic ASP Databases 1 November 6th, 2004 04:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.