L
Lars-Erik Aabech
Hi!
I've been scratching my head for a while not getting there...
If you have a method that instanciates an SqlConnection, what is neccesary
to do in the errorhandling part to clean up connections and memory - if that
is neccesary to do at all
Consider the following, and you will see my dilemma:
public DataSet someMethod(object someParameter)
{
SqlConnection cn;
try
{
cn.Open("...");
//... some more code
}
catch(Exception ex)
{
// Will the framework do this by it self, or is this a good thing to
do?
if (cn.State != ConnectionState.Closed)
try { cn.Close(); } catch { }
// And this....
cn = null;
throw(ex);
}
}
If I didn't try/catch at all.. would the connection close if the error
occurs after Open(), and would the garbage collector clean up the resources
immediately?
(ok, I could read a book - feel free to reccommend, but please help me
understand this too )
Lars-Erik
I've been scratching my head for a while not getting there...
If you have a method that instanciates an SqlConnection, what is neccesary
to do in the errorhandling part to clean up connections and memory - if that
is neccesary to do at all
Consider the following, and you will see my dilemma:
public DataSet someMethod(object someParameter)
{
SqlConnection cn;
try
{
cn.Open("...");
//... some more code
}
catch(Exception ex)
{
// Will the framework do this by it self, or is this a good thing to
do?
if (cn.State != ConnectionState.Closed)
try { cn.Close(); } catch { }
// And this....
cn = null;
throw(ex);
}
}
If I didn't try/catch at all.. would the connection close if the error
occurs after Open(), and would the garbage collector clean up the resources
immediately?
(ok, I could read a book - feel free to reccommend, but please help me
understand this too )
Lars-Erik