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

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

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: Newest
  1. Gerald Oakham 81 Reputation points
    2022-06-24T12:46:26.65+00:00

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

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

    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.

  3. Olaf Helper 27,211 Reputation points
    2022-06-24T10:44:01.857+00:00

    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.