C# , ADO.NET - Better to recreate a SqlCommand object each time it's used or to keep the object around?
Posted on 2013-01-24
I'm working on a C# console app with some classic ADO.NET in which I'm making a ton of calls to a MSSQL database. When I fire up the application, I instantiate a SqlConnection object (we'll call it mySQLConnection) and keep it around until the console app is done. That seems reasonable. My question centers on my SqlCommand object (we'll call it mySQLCommand). Is it better practice to create one mySQLCommand object, use it again and again, and then dump it when the console app is done. Or, is it better practice to create a new instance of SqlCommand each time I need to execute a command?