PC Review


Reply
Thread Tools Rate Thread

Close an active ODBC connection

 
 
Jeff
Guest
Posts: n/a
 
      5th Oct 2009
I've got a connection to a SQL database that I create when I update the
source data. I keep it open to run multiple queries from the same source but
I want to close it when I close the workbook.

How can I close an active connection that was created and maintained in a
different sub-routine?


 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      5th Oct 2009
How are you keeping it opened? Is ther are Public or Static variable that
you are using?

If ther is a variable associated with the connection then simply create a
workbook close event, close the conection variable, and then set the
Connection variable to equal nothing.

"Jeff" wrote:

> I've got a connection to a SQL database that I create when I update the
> source data. I keep it open to run multiple queries from the same source but
> I want to close it when I close the workbook.
>
> How can I close an active connection that was created and maintained in a
> different sub-routine?
>
>

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      5th Oct 2009
I have a subroutine that creates the connection. The connection can take a
little bit to open (I'm assuming it's a network thing) so I don't want to
keep opening and closing it. That's why I thought it would be easier to open
it once and close it when I'm done with it.

The programmer does it this way through Visual Basic for the same reasons.


"Joel" wrote:

> How are you keeping it opened? Is ther are Public or Static variable that
> you are using?
>
> If ther is a variable associated with the connection then simply create a
> workbook close event, close the conection variable, and then set the
> Connection variable to equal nothing.
>
> "Jeff" wrote:
>
> > I've got a connection to a SQL database that I create when I update the
> > source data. I keep it open to run multiple queries from the same source but
> > I want to close it when I close the workbook.
> >
> > How can I close an active connection that was created and maintained in a
> > different sub-routine?
> >
> >

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      5th Oct 2009
Are you sure you are keeping the connection open after the macro finishes?
VBA doesn't normally retain connections when a macro ends. That is why I'm
asking? If it is automatically closing when the macro finishes, then you
don't need to close it again. You'll just get an error.

"Jeff" wrote:

> I have a subroutine that creates the connection. The connection can take a
> little bit to open (I'm assuming it's a network thing) so I don't want to
> keep opening and closing it. That's why I thought it would be easier to open
> it once and close it when I'm done with it.
>
> The programmer does it this way through Visual Basic for the same reasons.
>
>
> "Joel" wrote:
>
> > How are you keeping it opened? Is ther are Public or Static variable that
> > you are using?
> >
> > If ther is a variable associated with the connection then simply create a
> > workbook close event, close the conection variable, and then set the
> > Connection variable to equal nothing.
> >
> > "Jeff" wrote:
> >
> > > I've got a connection to a SQL database that I create when I update the
> > > source data. I keep it open to run multiple queries from the same source but
> > > I want to close it when I close the workbook.
> > >
> > > How can I close an active connection that was created and maintained in a
> > > different sub-routine?
> > >
> > >

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      6th Oct 2009
I got it working and the connection speed isn't prohibitive so I don't need
to solve this problem.

Thanks anyway.

Jeff

"Joel" wrote:

> Are you sure you are keeping the connection open after the macro finishes?
> VBA doesn't normally retain connections when a macro ends. That is why I'm
> asking? If it is automatically closing when the macro finishes, then you
> don't need to close it again. You'll just get an error.
>
> "Jeff" wrote:
>
> > I have a subroutine that creates the connection. The connection can take a
> > little bit to open (I'm assuming it's a network thing) so I don't want to
> > keep opening and closing it. That's why I thought it would be easier to open
> > it once and close it when I'm done with it.
> >
> > The programmer does it this way through Visual Basic for the same reasons.
> >
> >
> > "Joel" wrote:
> >
> > > How are you keeping it opened? Is ther are Public or Static variable that
> > > you are using?
> > >
> > > If ther is a variable associated with the connection then simply create a
> > > workbook close event, close the conection variable, and then set the
> > > Connection variable to equal nothing.
> > >
> > > "Jeff" wrote:
> > >
> > > > I've got a connection to a SQL database that I create when I update the
> > > > source data. I keep it open to run multiple queries from the same source but
> > > > I want to close it when I close the workbook.
> > > >
> > > > How can I close an active connection that was created and maintained in a
> > > > different sub-routine?
> > > >
> > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close ODBC Connection / DSN vs DSN-less Connection / Access 2k2 Front-End Greg Strong Microsoft Access 8 10th Jul 2006 06:32 AM
ODBC Error 3151 on conection of MYSql ODBC Connection =?Utf-8?B?a2ZzY2hhZWZlcg==?= Microsoft Access VBA Modules 0 24th Mar 2006 07:45 PM
odbc connection won't close =?Utf-8?B?cGF0cmlja2hvZWxzY2hlcg==?= Microsoft Excel Discussion 0 27th Feb 2006 03:05 PM
Excel shoud not close all active books when clicking close button =?Utf-8?B?dGVjaG5vbWlrZQ==?= Microsoft Excel Misc 0 10th Jun 2005 05:35 PM
Have to close Access or wait 10 minutes for ODBC to close Steve Microsoft Access External Data 0 21st Jan 2004 01:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.