>The SqlConnection will close when it exits the using clause.No, I don't think so ... I'm pretty sure that even though the oConn object goes out of scope, the connection will remain open.
~~Bonnie
>>>>>In other words, if you use this syntax, the connection object is automatically closed.
>>>>
>>>>Ok, I see. But I'm not sure how to use it in my class. Can you elaborate a bit?
>>>
>>>I don't know if this is applicable in your class and I'm not 100% sure the syntax will work as is.
>>>
>>>Can you post a bit of code how you're using this method in your code right now and we'll see, if my idea can work for you or not.
>>
>>
>>Sure. It's a bit long tho...
>>
>
>Here's your code, with the using statement:
>
>
>public SqlDataReader ExecuteReader(string sCommand, ArrayList colParams, CommandType Type)
>{
>
> SqlDataReader oRetVal = null;
>
> using (SqlConnection oConn = _GetConnection(true))
> {
> if (oException == null)
> {
> SqlCommand oCommand = new SqlCommand();
>
> oCommand.Connection = oConn;
> oCommand.CommandText = sCommand;
>
> if (colParams != null)
> {
> SqlParameter[] aParams = new SqlParameter[colParams.Count];
> colParams.CopyTo(aParams);
>
> oCommand.Parameters.Clear();
> oCommand.Parameters.AddRange(aParams);
> }
>
> oCommand.CommandType = Type;
>
> try
> {
> oRetVal = oCommand.ExecuteReader();
> }
> catch (SqlException e)
> {
> _oException = e;
> }
>
> if (_oException == null)
> {
> oCommand.Parameters.Clear();
> }
> }
>
> return oRetVal;
> }
>}
>
>
>The SqlConnection will close when it exits the using clause.
>
>Still, even with your code, I would think that you should be able to use oConn.Close() at the end of ExecuteReader method, though I haven't tried it.