The method 'EndExecuteNonQuery' cannot be called more than once for the same execution.

asked 2022-06-24T10:05:04.007+00:00
Gerald Oakham 81 Reputation points

Hi,
I am trying to create a program that will back up a database, and then restore this backup to a different name (orginalDatasbaseName_training).
The backup part works Ok, but when this finishes I get a "'EndExecuteNonQuery' cannot be called more than once", and when the Training creation process starts also, then I get the same message.
I've tried adding a "command.EndExecuteNonQuery" at the end of the backup section, and putting the training creation put into its own connection ( and the opening and closing of a connection after each of the training procedures SQL lines), but I still get the same error.
214689-creatingtrainingdb.txt

Many Thanks
Nb: file attached as I was unable to copy code into Post.

No comments
{count} votes

3 answers

Sort by: Most helpful
  1. answered 2022-06-24T10:44:01.857+00:00
    Olaf Helper 25,551 Reputation points

    I've tried adding a "command.EndExecuteNonQuery" at the end of the backup section,

    And what should that be good for?
    The execution automatically ends when the backup has finished.

    No comments

  2. answered 2022-06-24T11:20:13.74+00:00
    Gerald Oakham 81 Reputation points

    Hi,
    but after the backup it produces the "'EndExecuteNonQuery' cannot be called more than once for the same execution." message , and if an option is ticked, when its tried to recover the newly created backup into another database, it fails with the same message.

    No comments

  3. answered 2022-06-24T12:46:26.65+00:00
    Gerald Oakham 81 Reputation points

    many thanks to everyone. I believe I have resolved this (too many EndExecuteNonQuery lurking in the code. :-)

    No comments