469,299 Members | 2,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

use an oledbconnection on more than one form

hcs
Hello,

i have got a form working which displays data from an access database. is it
possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers
Nov 21 '05 #1
6 1148
Yes it is possible to share connections. But do remember that ADO.NET will
pool the connections for you automatically, and in most cases it makes sense
to let ADO.NET pool the connections for you rather than you pooling them
yourself. It could be argued that for a winforms app connection pooling is
uneccessary but I digress especially because by not connection pooling you
lock yourself in a bad architecture that prevents you from remtoing part of
your application to an app server and sharing connections in a database
layer over there as the demands of your application continue to grow.

Even if you were to pool the *instance* of the connection object, you'd only
be pooling the instance, not the underlying connections (which is what you
really want to do). To do that you'd have to explicitly disable connection
pooling.

Now if you still insist on sharing connections, you'd have to expose the
connection objects from this form as public variables and let the other form
access them via an instance of this form. If it is an MDI application or
similar, it may make sense to keep these connections as the logical
equivalence of global variables on the main parent form and pass the
references to the child forms.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is it possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers

Nov 21 '05 #2
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure
that you close all those bad boys once their opened so they are returned to
the pool

In VB you can create the datasets- adapters etc as either shared properties
or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is it possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers

Nov 21 '05 #3
hcs
Thanks you have helped point me in the right direction

"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is
it possible to share the connections, dataadapter and datasets that have
been setup in this form on another form???

Cheers

Nov 21 '05 #4
KSC
Related Question...
Is the connection always open after it is created (until you explicitly
close it) or does VB open when you make change with a DataAdapter and close
it immediately?

"W.G. Ryan eMVP" wrote:
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure
that you close all those bad boys once their opened so they are returned to
the pool

In VB you can create the datasets- adapters etc as either shared properties
or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is

it
possible to share the connections, dataadapter and datasets that have been
setup in this form on another form???

Cheers


Nov 21 '05 #5
Remember connection object != actual db connection. Connection object sits
on top of a connection pool.

If you simply create a connection object, that object's state is closed ..
HOWEVER .. there might be one or more open connections in the connection
pool underneath.

If you call a dataadapter.fill, and pass it a connection *object*, it
changes it's state to Open, fills, and Close.

Now, when it calls Open, what happens behind the scenes is - it checks if
there is an available and idle open connection in the connection pool. if
there is, it hands it over, else opens a brand new one. But to your
application, it won't even notice the difference - except in better
performance maybe.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"KSC" <KS*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
Related Question...
Is the connection always open after it is created (until you explicitly
close it) or does VB open when you make change with a DataAdapter and close it immediately?

"W.G. Ryan eMVP" wrote:
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure that you close all those bad boys once their opened so they are returned to the pool

In VB you can create the datasets- adapters etc as either shared properties or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is
it
possible to share the connections, dataadapter and datasets that have

been setup in this form on another form???

Cheers


Nov 21 '05 #6
Remember connection object != actual db connection. Connection object sits
on top of a connection pool.

If you simply create a connection object, that object's state is closed ..
HOWEVER .. there might be one or more open connections in the connection
pool underneath.

If you call a dataadapter.fill, and pass it a connection *object*, it
changes it's state to Open, fills, and Close.

Now, when it calls Open, what happens behind the scenes is - it checks if
there is an available and idle open connection in the connection pool. if
there is, it hands it over, else opens a brand new one. But to your
application, it won't even notice the difference - except in better
performance maybe.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"KSC" <KS*@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
Related Question...
Is the connection always open after it is created (until you explicitly
close it) or does VB open when you make change with a DataAdapter and close it immediately?

"W.G. Ryan eMVP" wrote:
Like Sahil says- the answer is yes. However with the connection - just
share the connection string and instead of sharing the connection make sure that you close all those bad boys once their opened so they are returned to the pool

In VB you can create the datasets- adapters etc as either shared properties or stick them in a module (which is the same thing under the hood).

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"hcs" <a@a.co.uk> wrote in message
news:ek**************@TK2MSFTNGP14.phx.gbl...
Hello,

i have got a form working which displays data from an access database. is
it
possible to share the connections, dataadapter and datasets that have

been setup in this form on another form???

Cheers


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matthias Kwiedor | last post: by
2 posts views Thread by Grant | last post: by
2 posts views Thread by Roger Cantillo | last post: by
reply views Thread by Tony Johansson | last post: by
6 posts views Thread by bokiteam | last post: by
7 posts views Thread by Miro | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.