Connection Pooling

S

Sylvie

I have a static function in a class, everytime I call this function, I am
creating a SQLconnection, open it, use it, and null it, All my functions and
application logic is like this,

Every connection is creating self connection object and null it after the
some process,

Is this wrong ?

One of my friend told me about "Connection Pooling", and I am confused
enough, Only one connection can be used in all part of the applicaton
(whether web or windows application)

//

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public class Langs

{

public Langs()

{

}

public static void GetLanguageList()

{

SqlConnection ConnLocal = new
SqlConnection(DataFace.GetSQLConnectionString());

try

{

SqlCommand CommLocal = new SqlCommand();

CommLocal.Connection = ConnLocal;

CommLocal.CommandText += "SELECT bla bla bla";

ConnLocal.Open();

SqlDataReader rdLocal =
CommLocal.ExecuteReader(CommandBehavior.CloseConnection);

if (rdLocal.HasRows)

{

while (rdLocal.Read())

{

}

if (rdLocal.IsClosed != false)

{

rdLocal.Close();

}

}

catch (Exception Exx)

{

throw Exx

}

finally

{

ConnLocal = null;

}

}

}
 
W

William Vaughn

See www.betav.com/blog/billva and search for "pooling" or "connecting".

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
J

JonOfAllTrades

Sylvie said:
I have a static function in a class, everytime I call this function, I am
creating a SQLconnection, open it, use it, and null it, All my functions and
application logic is like this,

Every connection is creating self connection object and null it after the
some process,

Is this wrong ?

I can't speak for pooling, but don't you need to either Close() your
SqlConnections, rather than just cutting them off? The server will kill them
automatically, eventually, but you may generate hundreds of connections
first, and that can be a performance hit. Perhaps the GC and Dispose() will
take care of it, but that might not happen right away, either.
 

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