AccessDataSource class practically inherits from SqlDataSource. It's main
purpose is to make it easier (Access-like) to connect to the database, but
there's nothing that AccessDataSource can do but SqlDataSource couldn't
(actually it's opposite for example Access dbs protected with username or
password, must be connected with SqlDataSource, AccessDataSource cannot
handle them since it doesn't you to set the connection string)
Rules related to connection state are that you should open the connection as
late as possible (just before it's used) an close it as soon as possible
(after it's been used). You can use same connection for multiple db
operations (and keep connection open) if the operations are executed within
same method / scope so that connection isn't created muleiple times within
the scope, but there's no need to try to reduce instantiation of connections
for db operations with wider scope than that. For example say opening
connection in Page_Load and reusing it in all operations till Page_PreRender
runs, when you'd close the connection, you shouldn't do anything like that.
Connection pooling mechanism is very efficient, is also employed
automatically, and in fact is better controlling the resources than trying
to "help" the system with forcing connection to stay open is.
For more information about connection pooling,see:
http://msdn2.microsoft.com/en-us/library/8xx3tyca.aspx
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
<ms******@bluewin.chwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>I use an Access db in my application. So far I have been exclusively
working wtih the AccessDataSource controls to hook up to the db. I
know that Access db connections can also be established with
SqlDataSource.
What are the trade-offs between the AccessDataSource and SqlDataSource?
Also, I am confused about the connection state. What are the rules of
thumb for maintaining a db connection open vs closing it?
Thanks for any hints, Mark