Database update

  • Thread starter Thread starter Maziar Aflatoun
  • Start date Start date
M

Maziar Aflatoun

Hi,

To update the database I first open a connection, update and then I close
it. Is there way to do this without opening the connection first? Such as
using the DataAdaptor (which manages the connection automatically)? Is that
efficient?

Thanks
Maz.
 
...
To update the database I first open a connection, update and
then I close it. Is there way to do this without opening
the connection first?

No, you always need a Connection, which however could be hidden in some kind
of proxy.
Such as using the DataAdaptor (which manages the
connection automatically)?

Do you mean a DataAdapter?
It would still need a Connection.
What DataAdapter do you get "automatic connections" with?
Is that efficient?

Probably not, but it is rather a question of what you actually want to
accomplish, i.e. how these updates relate to each other.

A DataAdapter is used as a bridge between a DataSet and the DB, so if you
want to update "through" a DataSet, a DataAdapter can be the way to go, but
if you don't need a DataSet, then a plain "open, update and close" should be
more efficient.

// Bjorn A
 
You will have to specify the connection that the DataAdapter will use but the
data adapter will handle the opening and closing of the connection for you.

The DataAdapter can be more efficient but it depends on what you are doing.
Whether or not you should use the DataAdapter depends completely on your
particular needs and situation.


--
Brian Delahunty
Ireland

http://briandela.com/blog

INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
started in the southeast of Ireland.
 
DataAdapter does the same thing you would do - it opens a connection
and then closes it when it's done. The choice is yours and really
depends on the particular business logic.

You can't communicate with a database unless there is an active
connection to do so with.
 
You don't need to be overly concerned with opening and closing connections;
under the hood, connection pooling is used so that there isn't the overhead
you'd expect from opening and closing connections.

If an application is performing lengthy bulk operations of some kind, I'll
hold an open connection for all the work, possibly even for the duration of
an app dedicated to such an operation. But other than that, for typical web
apps, etc., just open a connection, do what needs doing, and close it. That
is what the DataAdapter does by default anyway. This keeps your code simple
and minimizes resource usage in the long run.

--Bob
 
Back
Top