Re: Closing an Access OleDBConnection from another Form by pooba53
pooba53
Tue Mar 20 10:16:03 CDT 2007
Thanks, Robin. I'll be able to incorporate one of these options for
sure!
Take care.
-Dan
On Mar 18, 6:36 pm, "RobinS" <Rob...@NoSpam.yah.none> wrote:
> Here are some options, sort of in order of preference:
>
> 1) Close the connection before you close or leave Form1, because
> technically in .Net in most cases you shouldn't leave your connections open
> all the time anyway. (This has been a public service announcement. I
> include this to help head off all the posts condemning you for wanting to
> leave your connection open. Let's go on now. ;-)
>
> 2) Add a public method to Form1 to close the connection, call it from
> Form2.
>
> (The Vegas theory: What happens in Vegas, stays in Vegas. How to apply this
> to .Net: What connection is opened in Form1, is closed in Form1.)
>
> 3) Make the connection a public property on Form1, and close it directly
> from Form2.
>
> 4) Pass a reference to the connection to Form2 in its constructor, then
> close it in Form2.
>
> 5) Make the connection global and add global open and close methods that
> can be accessed anywhere.
>
> Robin S.
> ---------------------------------"pooba53" <poob...@gmail.com> wrote in message
>
> news:1174249716.764372.147370@d57g2000hsg.googlegroups.com...
>
> >I have Form1 that has two OleDBconnections to an Access database.
>
> > I have Form2 that has a function that requires the Access db be
> > disconnected from my application. My Form2 knows nothing about the db
> > connections in Form1 obviously.
>
> > How do I close the open dbconnections from Form2 when they are
> > associated with Form1?
>
> > Thanks much!