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 September 24th, 2007, 08:14 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Default close sql connection

hello to all
i am finding my self in confusing problem.

everyay log file of my application increase by 10 GB.
every time i found more than 100 connections open in SDQL Server 2005 under my database.

i an using SQLHELPER Class by microsoft.i ma not putting my code in try-catch block. example

of one of my frequently used function is as follows:

        protected Int64 GetMemberID()
        {
            String SqlSelect = "SELECT * FROM MemberMaster WHERE MemberUserName= '" +

Session["UserName"].ToString() + "'";
            SqlDataReader dr1 =

SqlHelper.ExecuteReader(ConfigurationManager.Conne ctionStrings["CowcallConnectionString2"].T

oString(), CommandType.Text, SqlSelect);
            while (dr1.Read())
            {
                CurrentMemberID = Int64.Parse(dr1["MemberID"].ToString().Trim());
            }
            return CurrentMemberID;
        }

well i doubt i am opening connection and do not closing it. moreover i do not know how to close connection in above code when i am using sql helper class.
please give me yours suggestion regarding my code even if it is not solving above two problems.

thanks......
__________________
thanks......
 
Old September 24th, 2007, 09:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. I don't know how the helper class work, but when you use a reader you have a connection object and a command object open.. so after you use the reader you have to dispose them somewhere.. so maybe you have a method to do that???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 26th, 2007, 01:13 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Supporting Gonzalo, there is a property with datareader as "CommandBehavior.CloseConnection" which automatically closes the connection once data is fetched, so study that...

Regards
Mike
 
Old September 27th, 2007, 10:32 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Default

thanks i try this.
i want to know if i am not to use sqlhelper class. what's other way to access connection string and use SQL query. is i am to write again and again

thanks......





Similar Threads
Thread Thread Starter Forum Replies Last Post
When should you close the database connection? Stickannn Pro PHP 0 September 13th, 2007 04:25 AM
ASP / ADODB - How to close connection? hamproof Classic ASP Databases 4 August 24th, 2007 01:43 PM
sqldatareader close connection mdonner BOOK: Beginning ASP.NET 1.0 2 July 5th, 2007 04:50 AM
Command Object -- How to close db connection? wolfpack391 Classic ASP Databases 4 July 31st, 2004 05:28 AM
Open/Close SQL Connection within every method? flyin ADO.NET 8 May 18th, 2004 07:19 AM





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