Dispose() Question?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a SqlConnection object , Dose calling Dispose() in SqlConnection
Object close the opened connection to database?

Other: When I need to implement IDisposal interface?
 
Raed,

I always do these instructions below regardless (it never broke):

if(mySQLConnection.State==ConnectionState.Open)
mySQLConnection.Close();
mySQLConnection.Dispose();

BTW: Dispose() is good because you yourself tell the "clr" that it is no
longer useful.

John
 
Raed Sawalha said:
I have a SqlConnection object , Dose calling Dispose() in
SqlConnection Object close the opened connection to database?

Yes. With reflection you an read the method Diponse in SqlConnection class:
protected override void Dispose(bool disposing)
{
if (disposing)
{
switch (this._objectState)
{
case ConnectionState.Open:
{
this.Close();
break;
}
}
this._constr = null;
}
base.Dispose(disposing);
}
 
Hi Andrea Zani,

I have a question from your posting.

Is it possible to get the code of a method using reflection?

How did you get the code of the Dispose method of the SqlConnection class?
--
Saravanan K V


Andrea Zani said:
Raed Sawalha said:
I have a SqlConnection object , Dose calling Dispose() in
SqlConnection Object close the opened connection to database?

Yes. With reflection you an read the method Diponse in SqlConnection class:
protected override void Dispose(bool disposing)
{
if (disposing)
{
switch (this._objectState)
{
case ConnectionState.Open:
{
this.Close();
break;
}
}
this._constr = null;
}
base.Dispose(disposing);
}

--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
 
Back
Top