invalid cursor state SQLPrepare (after select)

Posted on 2005-04-15
Last Modified: 2007-11-27
Hi experts,

I perform 2 statements:  Select and then insert.

The select works fine and in my SQLPrepare(hStatement) for the insert, I get the error.

If I don't do my select, my SQLPrepare and execute on my insert works fine.

Any ideas???

Thanks - and 500 points to the person who helps!  =)

Question by:mikexpert
    LVL 33

    Expert Comment

    This doesn't look like a problem with MySQL. You might get a better answer in the appropiate language TA, such as MFC.

    Author Comment

    yep - thanks...

    Author Comment

    ok snoyes_jw - here's the real issue:

    I execute two queries:  one is a select and the other following one is an insert.

    The SELECT works fine but then I get the error in in my SQLPrepare for the INSERT.  If I omit the SELECT, I don't get an error in the INSERT...

    Any ideas???

    Thanks so much... and you're already gonna get the points for this question... (promise).. If you're able to answer this new one, I've posted it in two places - you'll get a total of 1500 points (this question plus two of the new one I'm asking you)...  (I don't really know if you care about points - but I hope you do!)   =)

    Thanks a bundle!

    LVL 33

    Accepted Solution

    SQLPrepare is not a MySQL thing; it is specific to some programming language(s), and not any that I know.  You haven't even mentioned which language you are using, and you might have confused MySQL with the Microsoft SQL or SQL Server areas.

    A few moments on Google reveals the following, any of which no doubt mean more to you than they do to me:

    - You cannot reuse the Statement Handle when the cursor is in use in this memory table.  Try to free the statement handle using some sort of "FreeStatement" function.

    - SELECT statements return a result set; INSERTS do not.  Perhaps using the SELECT first sets the handler to expect a result set; when none is returned with the INSERT, the error is raised.

    - If you're really using SQL Server, take a look here:

    Incidentally, in an attempt to curb "point inflation", the maximum legal points for any one question is 500.  That includes asking the same question in multiple areas.

    I recommend that you post in the Community Support area and ask a moderator to delete and refund this question, and then post in the topic area related to whatever programming language you are using.

    Author Comment

    Thanks for the help

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi ( had suggested a “sed” way, I actually shell …
    Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API ( …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now