none
SqlCommand in prepared state throw an error: "Could not find prepared statement with handle -1" RRS feed

  • Question

  • We have a customer where our server is behaving quite strange, after some investigation I have found that we have multiple SqlCommands in a broken state. The command state is Prepared, but _prepareHandle is -1, so when the command is executed we get SQL error “Could not find prepared statement with handle -1”.

    We are preparing commands and cached them, so they can be alive for quite long time.

    How can it be that a handle is -1? Can ADO.NET reset handle to -1, and not change command state?

    System.Data version is 4.0.0.0 And customer is using SQL 2014 RTM.

    Monday, September 12, 2016 12:13 PM

All replies

  • Hi AleksandrMalafeev,

    According to your descriptionand error message, i'm not sure what could cause the issue, could you please provide a bit more information about the issue, such as related code and related database table structure. we'll reproduce your issue on our side and try to find a solution to resolve it.


    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, September 13, 2016 1:17 AM
    Moderator
  • It is quite hard to do :) This is the code of the large ERP system. And I don't have an access to the customer database. But I have a server dump where I can see SqlCommand state. If you want to take a look to it, you can find me in Skype For Business (or in outlook, i'm also MS employee) by name. And I can share screen with you. I'm in GMT  +1 time zone.

    Aleksandr Malafeev

    Tuesday, September 13, 2016 9:24 AM
  • Hi Aleksandr Malafeev,

    I'm in GMT +8 time zone.

    I would suggest that you could create a simple demo which could reproduce the issue. And the provide the demo to us via OneDrive. we'll reproduce your issue on our side and try to find a solution to resolve it.

    Thank you for your understanding.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 14, 2016 2:39 AM
    Moderator
  • If i were able to repro it with simple demo, I wouldn't be asking on the forum :) I will then just fix it or open a bug for ADO.NET team. The problem that it reproes only with one customer, and I am just interested in the theoretical explanation how it can happen, is it ADO.NET problem or it could be a bug in ODBC driver, or it could be an SQL Server issue? It will be nice to know if anybody else experienced such problem and knows what can be the reason.
    Wednesday, September 14, 2016 9:12 AM
  • Hi Aleksandr Malafeev,

    I would suggest that you could record some records by using log4net. Then you could analyze the log records and check what data could cause the issue. and then you could reproduce the issue by using related data records

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 19, 2016 6:10 AM
    Moderator