Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2007, 04:57 AM
Authorized User
 
Join Date: Aug 2006
Posts: 39
Thanks: 1
Thanked 0 Times in 0 Posts
Default Connection Pooling problem.

Hi, I have an issue with following code. When this code is executed it shows open connection in my database of Sql Server. I run the 'EXEC SP_WHO' in sql query analyzer. How to actually close reader and connection? Please help me.....

    protected void button1_Click(object sender, EventArgs e)
    {
        SqlDataReader dr;
        dr = GetReader("2");
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();

        // same code continues for different GetReader many times

    }

    private SqlDataReader GetReader(string strTran)
    {
        SqlConnection con = new SqlConnection(MyConnectionString);

        SqlCommand cmd = new SqlCommand("Reports", con);
        cmd.CommandType = CommandType.StoredProcedure;

        //do something here.

        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        return dr;
    }

 
Old July 5th, 2007, 06:55 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:SqlDataReader dr = cmd.ExecuteReader();
Use the below which will close the connection once the data is fetchted:

SqlDataReader dr = cmd.ExecuteReaderCommandBehavior.CloseConnection);

Regards
Mike

Don't expect too much, too soon.
 
Old July 9th, 2007, 02:12 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Default

closing connection is necessary otherwise it will throw connection pooling problem otherwise (not very good idea), for temporary purpose, alter web.config file and write max pool size=40000 say in connection string, but closing connection is best approach.

thanks......





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection Pooling nigam.anand Apache Tomcat 0 October 18th, 2006 08:39 AM
Connection pooling and Timeout Raghavendra_Mudugal SQL Server 2000 2 May 24th, 2006 01:42 AM
connection pooling error aravwind ADO.NET 0 November 23rd, 2005 07:20 AM
Connection pooling in VB vijayma VB How-To 0 March 18th, 2005 03:51 AM
Connection Pooling with Beans angrycat Apache Tomcat 4 September 16th, 2004 06:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.