473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

HELP: CommandBehavior.CloseConnection

I have a data access component that returns a SqlDataReader object.

public SqlDataReader GetFeaturedArtists()
{
SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"])
using(SqlCommand cmd = new SqlCommand(
"SELECT artistName, ar.artistId "+
"FROM featuredArtist fa "+
"JOIN artist ar ON fa.artistId=ar.artistId"
))
{
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}
}

For obvious reasons I can't enclose the SqlConnection in a "using" statement
else the connection will be closed when this method returns.

Now, the returned SqlDataReader is bound to a DataGrid in one of my ASP
pages...

private void Page_Load(object sender, System.EventArgs e)
{
ArtistDALC artistDALC = new ArtistDALC();
DataGridFeaturedArtist.DataSource = artistDALC.GetFeaturedArtists();
DataGridFeaturedArtist.DataBind();
}

Now my question is, when the grid has read the data returned from the
SqlDataReader, the connection gets closed *but* does the Dispose method of
the SqlConnection object also get called?

Any help much appreciated...

--
Best regards
Mark Baldwin
Software Developer

Nov 17 '05 #1
0 1132

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Irfan Akram | last post by:
I keep getting this irritating exception on and on. Please Help. There is already an open DataReader associated with this Connection which must be closed first. Description: An unhandled...
5
by: dave | last post by:
I am calling a shared fucntion within a class from codebehind with asp.net. The class returns a sqldatareader to be bound to a datalist. I am also utilizing ms applicationblocks. How can I return...
10
by: Joe | last post by:
Hi, Tried using the FindControl() but no luck in finidng this damn textbox having id txtFirstName. Can someone help me with this method? This is what I have been doing but it doesn't work, ...
6
by: Sparky Arbuckle | last post by:
web.config <?xml version="1.0" encoding="utf-8" ?> <configuration> <!-- application specific settings --> <appSettings> <add key="myConnection" value="Provider=Microsoft.Jet.OLEDB.4.0;Data...
2
by: TG | last post by:
Hi, I am having a problem tryin to open the connection to a database the nretreiving the informaiton based on the entry of an email address and a password for authentication from the database. ...
4
by: the_kiddie98 | last post by:
Hi Guys, I was brought in at the last moment to try to get a project completed. it's vb.net and crystal reports. Here's the problem I can populate a parameter list for a report so the user can...
1
by: teddymeu | last post by:
hi guys I posted the other day regarding a solution i needed to design, im new to development an asp,net and built a local post office search tool using asp.net 2. vb in visual studio, using an...
8
by: maddy | last post by:
dear folks, i uploaded the image using the following code : HttpPostedFile myFile = Picture.PostedFile; int FileLen = myFile.ContentLength; string FName=Path.GetFileName (myFile.FileName);...
2
by: johnmay1248 | last post by:
I am having a problem with queries running in this code When I use the query "SELECT * FROM sample" the code runs and the data grid binds and shows the contents of the sample table. If I change...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.