Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 1st, 2005, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Alhambra, ca, USA.
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.



Reply With Quote
  #2 (permalink)  
Old December 3rd, 2005, 06:26 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:09 AM.


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