Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2004, 06:29 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to check if connection already exists

Hi guys

I'm connected to Oracle via an OLEDB Provider and I'm using ADO functionality.
I have a connection procedure (let's call it OpenLink) in one of my modules that is called by another function to issues SQL commands (lets call it SQLDirect) against the database using the connection.

I have several modules that call SQLDirect which in turn calls the OpenLink before issuing the statement against the database.

The SQLDirect and OpenLink functions are in one module and all other calls to SQLDirect are in a number of other modules

I need to be able to check if I have already opened a connection so that I don't open another when issuing a second call to SQLDirect.
How can I do this?

If I set a Public variable in the module, I presume this will be reset everytime any functions within this module are called.

Many thanks in advance

Cheers

Ciaran
 
Old March 9th, 2004, 08:34 AM
Authorized User
 
Join Date: Aug 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use:

adoConnection.State

This returns 1 of the connection is open and 0 if it is closed.

Greetz

Tom.
 
Old March 9th, 2004, 08:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you refer to modules are you referring to Dll's or simply class modules within your project?

If you are speaking fo class modules within your project there are several ways to accomplish this and the same could be true if the dll's are referenced within the same project/application.

Are you using a global connection object? In most of my application I use a global connection object and local recordset objects, if the application is data intensive. What I want to avoid, as well as having multiple connections for the same application, is the overhead of repeated connections to the database. So, I have a similar set of tools as you do - I use dll's. I will create a global database connection object at the project level and then connect to the application on startup for data intensive applications and then disconnect when the application shuts-down. For other application where that involve intermittent access to data I will use a connection function that check the state of the global database connection object. Usually, I will check to see if it is set to nothing if it is then I will call a function to create the connection and pass it the global connection object. If the connection object is not set to nothing then I simply execute my data logic. You may be better served by checking the State property of the connection object as well.

Hope this helps.

Larry Asher
 
Old March 9th, 2004, 10:24 AM
Authorized User
 
Join Date: Mar 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the replies Guys

Cheers

Ciaran





Similar Threads
Thread Thread Starter Forum Replies Last Post
check whether COM object exists EddyT C# 0 June 15th, 2007 04:10 AM
How to check if exists BEFORE the Insert rtr1900 Classic ASP Databases 0 December 20th, 2006 07:04 AM
check whether a particular session exists or not chayanvinayak PHP How-To 1 May 1st, 2006 04:09 PM
check first to see if the file exists crmpicco Classic ASP Professional 2 December 1st, 2005 12:34 PM
how to check that node is exists debuajm General .NET 0 June 8th, 2004 02:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.