Click here to Skip to main content
16,004,833 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: <form> on masterpage and user controls Pin
moazzamahmed13-Nov-06 11:52
moazzamahmed13-Nov-06 11:52 
QuestionInserting line numbers Pin
sudidela11-Nov-06 19:02
sudidela11-Nov-06 19:02 
QuestionGenerics & ViewState Pin
eggie511-Nov-06 17:41
eggie511-Nov-06 17:41 
AnswerRe: Generics & ViewState Pin
aamironline12-Nov-06 1:58
aamironline12-Nov-06 1:58 
Questionwhat is the opposite action for Fill(dataset) Pin
karanba11-Nov-06 14:48
karanba11-Nov-06 14:48 
AnswerRe: what is the opposite action for Fill(dataset) Pin
Guy Harwood12-Nov-06 11:18
Guy Harwood12-Nov-06 11:18 
Questionclosing a connection Pin
karanba11-Nov-06 14:01
karanba11-Nov-06 14:01 
AnswerRe: closing a connection Pin
Guffa11-Nov-06 14:21
Guffa11-Nov-06 14:21 
You should definitely close the connection. If you don't, the connection object will be lying around in memory, still connected, until the garbage collector is forced to finalize it.

If you run out of available connections before you run out of memory (which will cause a garbage collection), the server will be unable to connect to the database at all until some of the open connections eventually time out.

Objects in .NET are not finalized when they go out of scope, they are just left to be garbage collected. That's why there is a Dispose method in the first place. It's used to tell objects that you are done with them, so that they can release all unmanaged resources.

To make sure that the connection is always closed properly, you should use a using block. When you leave the using block, the connection is always disposed (which also closes it).

public static SqlDataAdapter dataAdapter(SqlCommand cmd, string connectionString) {
	SqlDataAdapter da;

	using (SqlConnection con = new SqlConnection(connectionString)) {
		cmd.Connection = con;
		con.Open();
		da = new SqlDataAdapter(cmd)
	}
	return da;
}



---
b { font-weight: normal; }

GeneralRe: closing a connection Pin
karanba11-Nov-06 14:49
karanba11-Nov-06 14:49 
QuestionPicture Gallery with paging Pin
mehrdadc4811-Nov-06 10:59
mehrdadc4811-Nov-06 10:59 
AnswerRe: Picture Gallery with paging Pin
karanba12-Nov-06 1:38
karanba12-Nov-06 1:38 
GeneralRe: Picture Gallery with paging Pin
kumarrani55529-Oct-12 21:56
kumarrani55529-Oct-12 21:56 
Questionweb.config Pin
neojapanese11-Nov-06 6:58
neojapanese11-Nov-06 6:58 
GeneralRe: web.config Pin
Guffa11-Nov-06 7:35
Guffa11-Nov-06 7:35 
GeneralRe: web.config Pin
RichardGrimmer13-Nov-06 2:59
RichardGrimmer13-Nov-06 2:59 
QuestionExcluding controls from localization Pin
Dario Solera11-Nov-06 4:28
Dario Solera11-Nov-06 4:28 
Questionsend var from client side to server side Pin
Imran Khan Pathan11-Nov-06 1:46
Imran Khan Pathan11-Nov-06 1:46 
AnswerRe: send var from client side to server side Pin
CWIZO11-Nov-06 2:12
CWIZO11-Nov-06 2:12 
GeneralRe: send var from client side to server side Pin
Imran Khan Pathan11-Nov-06 2:33
Imran Khan Pathan11-Nov-06 2:33 
AnswerRe: send var from client side to server side Pin
Guffa11-Nov-06 6:34
Guffa11-Nov-06 6:34 
Questionneed help on how to config web.config Pin
neodeaths11-Nov-06 1:45
neodeaths11-Nov-06 1:45 
QuestionHow to get current Year Value Pin
Sam.M11-Nov-06 1:38
Sam.M11-Nov-06 1:38 
AnswerRe: How to get current Year Value Pin
CWIZO11-Nov-06 1:43
CWIZO11-Nov-06 1:43 
GeneralRe: How to get current Year Value Pin
Sam.M11-Nov-06 1:49
Sam.M11-Nov-06 1:49 
GeneralRe: How to get current Year Value Pin
CWIZO11-Nov-06 2:11
CWIZO11-Nov-06 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.