> I'm writing a small 'learning' app. It uses SQL Server.
>
[quoted text clipped - 23 lines]
>
> Common.Database.Connect();

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
> It's better to open the connection when need it, and close it
> immediately after you've used it, e.g. in a using statement.
Thanks (again) John. Can you give an example of the Using?
I guess you mean if I have a 'getData' type function which I pass an
SQL statement to, and returns a recordset, then the getData would open
the connection, do the query, return the data and close the connection?
Jon Skeet [C# MVP] - 15 Jan 2008 21:10 GMT
> > It's better to open the connection when need it, and close it
> > immediately after you've used it, e.g. in a using statement.
>
> Thanks (again) John. Can you give an example of the Using?
The using statement is something like:
using (SqlConnection conn = new SqlConnection())
{
// Use conn here
}
// conn has automatically been closed (Dispose has been called) even
// if an exception is thrown
> I guess you mean if I have a 'getData' type function which I pass an
> SQL statement to, and returns a recordset, then the getData would open
> the connection, do the query, return the data and close the connection?
Exactly.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk