Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

Data Controls and Open Connections

Question:
I have five data controls on a form that access five tables from the same database. I want to open the database just once. Does having five data controls mean that the databse is opened five times? Is there any way to open the databse programatically and assign the resultant recordset to data controls? Does this ensure that the database is opened just once?

Answer:
For each data control you use (or dynaset), VB creates a connection to the database. You would have 5 active connections to the database in this case. This can become a problem if you have a database that monitors the number of connections in place of checking distinct users. (Oracle is one of the vendors whose database works like this.)

Under VB 4, you can open a database object using the OpenDatabase method. You can then create a recordset with OpenRecordset, and assign it to the Recordset property of the data control. Here's an example:

' dcData is a data control on the form.

Dim db as Database
Dim rs as Recordset

Set db = OpenDatabase("filename.ext")
Set rs = db.OpenRecordset("Table1", dbOpenDynaset)
Set dcData.Recordset = rs
That's all there is to it under VB4. Note that under VB3, you were not able to assign recordsets to data controls.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date