J
Joanna Carter [TeamB]
Hi Folks
..NET 2.0 and SQLServer2005
I am just trying to get my head around whether I can use a single
SQLConnection for the life of the application or whether I should create it
only when needed.
I want to create cached SQLCommand objects that are then prepared to reduce
subsequent execution time, but these can't be prepared unless their
Connection property has been set.
This then causes me to think that, if I create/dispose connections in a
"using" block, the vommands are going to keep a reference to the connection
alive anyway, so why not just keep the connection alive for the duration of
the application ?
If I make a connection for the first time, then prepare the commands, then
call Dispose on the connection, will the commands have to be prepared the
next time I instantiate the connection, using pooling ?
So I have two options :
1. Create connection, prepare commands on first call then keep them in a
list, only close connection when app closes
2. Create connection in "using" block, this then means I don't keep a list
of prepared commands and have to take the speed hit on running the commands
every time I get a new connection.
What is the better route ?
Joanna
..NET 2.0 and SQLServer2005
I am just trying to get my head around whether I can use a single
SQLConnection for the life of the application or whether I should create it
only when needed.
I want to create cached SQLCommand objects that are then prepared to reduce
subsequent execution time, but these can't be prepared unless their
Connection property has been set.
This then causes me to think that, if I create/dispose connections in a
"using" block, the vommands are going to keep a reference to the connection
alive anyway, so why not just keep the connection alive for the duration of
the application ?
If I make a connection for the first time, then prepare the commands, then
call Dispose on the connection, will the commands have to be prepared the
next time I instantiate the connection, using pooling ?
So I have two options :
1. Create connection, prepare commands on first call then keep them in a
list, only close connection when app closes
2. Create connection in "using" block, this then means I don't keep a list
of prepared commands and have to take the speed hit on running the commands
every time I get a new connection.
What is the better route ?
Joanna