Q) Another q re dataAccess Block

  • Thread starter Thread starter bill
  • Start date Start date
B

bill

In the DataAccess block example, they create a database connection in
GetConnection method of the sample form (Form1) which is called at the
beginning of each of their examples. But in their SQLHelper Class they also
create connections in many of the methods such as ExecuteDataset.

What's going on here?

Thanks
 
bill said:
In the DataAccess block example, they create a database connection in
GetConnection method of the sample form (Form1) which is called at the
beginning of each of their examples. But in their SQLHelper Class they also
create connections in many of the methods such as ExecuteDataset.

What's going on here?

For all of the methods that they expose in SqlHelper, there are multitudes
of overloads.

A basic operation (say ExecuteDataset) has overloads that take either: a
ConnectionString, a SqlConnection object or a SqlTransaction object. You
use the appropriate method that corresponds to what you happen to have (only
a connection string, an existing SqlConnection object or if you need a
transaction, a SqlTransaction object).

One note of caution... If you use the ConnectionString overloads, the call
itself destroys the connection (freeing the connection back to the
connection pool). If you use any of the others (and don't specify that the
call should 'manage' the connection itself, it WILL NOT free or close the
connection (i.e. it didn't create it so it won't free it). If you call the
methods lots of times, eventually you will exhaust the pool's supply of
connections and will receive a 'Timeout waiting for a connection" error
message.

HTHs...

John
 
Back
Top