• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Connection/DB thoughts

In order to improve performance, I would like to use the connect method just once, when the application starts, and then to use this connection with all other SQL commands I use. My problem is how can I send the connection object between forms, if it is possible ,because it seem like after the first openrecordset execution.
I use VB5 and Oracle7.3

  • 2
1 Solution

Yes it is possible to start one connection and pass it between forms, notice that the best way to deal with RDBMS is to use Microsoft Remote Data Object (RDO).


'Declare rdoCN as a global variable (in module1 for example)
Public rdoCN As New rdoConnection

'This code will be in form1
'Establish the connection
rdoCN.Connect = "uid=;pwd=;"DSN=WorkDB;"   'Replace WorkDB with your DSN
rdoCN.Cursordriver = rdUseOdbc
rdoCN.EstablishConnection rdDriverNoprompt 'Now rdoCN is our active connection

'This code will be in form2
Set RS = rdoCN.Execute("Select * from TestData")

'and before quiting the application you must close the connection
set rdoCN = Nothing

Best regards,
Bin Huwairib
oak022097Author Commented:
It doesn't help me because I am using the professional edition of VB.
OK, can you use DAO? If so, here is the way how to do it.
'Declare con as a global variable (in module1 for example)  
Public con As Connection

'This code will be in form1
Dim wrkODBC As Workspace

'Create ODBCDirect Workspace object.
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", "admin", "", dbUseODBC)

'Open Connection object
Set con = wrkODBC.OpenConnection("Connection1", _
            dbDriverNoPrompt, , _

'This code will be in form2
Dim rstTemp As Recordset
Set rstTemp = con.OpenRecordset( "SELECT * FROM stores", dbOpenDynamic)

'and before quiting the application you must close the connection

Best regards,
Bin Huwairib            
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now