In what situations is the SqlCommand preparation method useful?

Does anyone know that the ADO.NET SqlCommand object preparation method is useful in what situations?

+2


source to share


2 answers


  • If the underlying database supports it and
  • If you are going to call the same command (with different parameter values) multiple times. This way, you can save some time because the database can reuse the same query plan.


Typically modern database caching commands and query plans, but assuming your queries or commands are prepared, you can still save some time.

0


source


We're talking about SqlCommand, which implies Microsoft SQL Server. As far as I know, SQL Server has always supported it.

It is not clear, however, if he does anything useful. I haven't found anyone yet who really knows. Many people argue that it is nothing useful and there are no discernible performance differences. I would like to see evidence anyway.



On another database (Firebird using FbCommand object) I know this can cause problems if you're not careful. If you prepare an expression but never use it, the transaction will remain open forever. We had to remove all the pre-made files from our Firebird code. We had a habit of cooking anything that could be done multiple times.

+1


source







All Articles