Does SqlHelper automatically close SQL connection?

D

David Berman

Suppose I want to do something like populate a droplist control with
some data. I want to use as few lines of code as possible. In the
examples for the Microsoft Application Data block, it shows a few ways
of doing this.

(Note that Global.GetSqlDataSource(string) returns a SQL connection
string like this: "server=sqlserver.domain.com; uid=login;
password=pass")

CASE A:

// Execute stored procedure to load list of data labels
DataSet ds = SqlHelper.ExecuteDataset
(Global.GetSqlDataSource("DATA"),
CommandType.StoredProcedure, "usp_DataLabels_List");
dropDataLabels.DataSource = ds;
dropDataLabels.DataBind();

In case A, how does the SQL connection get closed? Does the connection
get closed after the dataset is assigned to ds? Or do I have to add
something? What would I need to add?


CASE B:

// Execute stored procedure to load list of data labels
dropDataLabels.DataSource =
SqlHelper.ExecuteReader(Global.GetSqlDataSource("DATA"),
CommandType.StoredProcedure,
"usp_DataLabels_List");
dropDataLabels.DataBind();

In this scenario, where is the connection closed? Or does it create a
leak?

If I want to keep code minimal, should I make an object that inherits
from SqlHelper, but calls this.Close() when it is finalized? Or do I
need to write more code to allocate a connection seperately and then
close it. Doesn't that defeat the purpose of the SqlHelper?

Thank you very much!

David




Meet people for friendship, contacts,
or romance using free instant messaging software! See a picture you
like? Click once for a private conversation with that person!

www.SEN.us
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top