B
Brandon Potter
Hi,
Basic SQL question.
I have your typical dynamic-content, about-10-SQL-requests-per-page web
site. However, I have run into some problems in the way that I'm doing
things in that sometimes the connection just fails, closes for no apparent
reason, or there's an open SqlDataReader somewhere, even though the code
does close every SqlDataReader when reading is finished.
I have created a SqlConnection object and opened the connection when the
user's session is created. For all the SQL requests that the pages make,
they just execute SqlCommands and SqlReaders using the one instance of
SqlConnection. When the session is done, I close the connection.
Should I be using the one instance of SqlConnection (my reasoning being that
it would be more efficient to hold the connection open rather than have the
extra load of opening and closing the connection), or should I be opening
and closing the connection for each SQL request? Or somewhere in between?
Thanks,
Brandon
Basic SQL question.
I have your typical dynamic-content, about-10-SQL-requests-per-page web
site. However, I have run into some problems in the way that I'm doing
things in that sometimes the connection just fails, closes for no apparent
reason, or there's an open SqlDataReader somewhere, even though the code
does close every SqlDataReader when reading is finished.
I have created a SqlConnection object and opened the connection when the
user's session is created. For all the SQL requests that the pages make,
they just execute SqlCommands and SqlReaders using the one instance of
SqlConnection. When the session is done, I close the connection.
Should I be using the one instance of SqlConnection (my reasoning being that
it would be more efficient to hold the connection open rather than have the
extra load of opening and closing the connection), or should I be opening
and closing the connection for each SQL request? Or somewhere in between?
Thanks,
Brandon