Using same SqlCommand to execute multiple commands RRS feed

  • Question

  • The Data Access Architecture Guide at mentions that



    Although you can repeatedly use the same SqlCommand object to execute the

    same command multiple times, do not reuse the same SqlCommand object to

    execute different commands.



    But it does not mention the reason behind this point. Does it affect the performance of the application? If so, how and why?


    I am working on improving performance of my application and hence need to know about it.



    Thursday, June 7, 2007 6:03 AM


  • It could be in a case if your command requires parameters. Basically you need to clear collection of the parameters (remove them completely and redefine them again) each time when you execute another SQL statement that requires new set of the parameters (not only new values). It is still possible, but probably code will not be as clean as you wish. Otherwise you still can execute multiple statements with the same command, you just need to be careful about cleaning resources associated with it

    Thursday, June 7, 2007 10:46 AM