Google Answers Logo
View Question
 
Q: Connection to SQL with VB6 ( No Answer,   2 Comments )
Question  
Subject: Connection to SQL with VB6
Category: Computers > Programming
Asked by: jstm-ga
List Price: $5.00
Posted: 13 Mar 2005 12:31 PST
Expires: 12 Apr 2005 13:31 PDT
Question ID: 493987
I am using the following connection code to SQL in my VB6 program:

   Set mconAP = New Connection
    Set mrsdatadb = New Recordset

mconAP.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=Online Reporting;Data
Source=MTQBQCQ"
    
    mrsdatadb.Open "Select * FROM [datadb] ORDER BY AutoIDdb", _
                    mconAP, adOpenKeyset, adLockOptimistic, adCmdText

I will have a large number of users working at the same time
(different computer stations) and was wondering if I am going to run
in to a problem?

I want the data to be readily available realtime so as soon as there
is a entry the data is available on the network...
Answer  
There is no answer at this time.

Comments  
Subject: Re: Connection to SQL with VB6
From: willcodeforfood-ga on 14 Mar 2005 11:20 PST
 
When you select data into your recordset, it is only a snapshot of the
data at the instant that the Open method ran.  Any subsequent updates
to the data that you selected will not be visible to your VB
application until you Open the recordset again.  If the datadb table
is very large, you may want to find a way to limit the number of rows
you are selecting by adding a where caluse and being as restrictive as
possible.  Also, since you are ordering your results by the AutoIDdb
field, you will want to make sure that it is indexed, unless the
AutoIDdb field is already the primary key or has a unique constraint
on it.

If your VB application is "looking" for new records or to simply see
if new records have been entered, then you could use an Identity field
in your SQL Server table to accomplish this.  Get the maximum value
from your table with:

Dim sql as String
sql = "Select max(AutoIDdb) as MaxID FROM [datadb]"
Dim lMaxId as Long
mrsdatadb.Open sql, mconAP, adOpenKeyset, adLockOptimistic, adCmdText
mrsdatadb.MoveFirst
lMaxID = mrsdatadb("MaxID")
mrsdatadb.Close ' be sure to close a recordset as soon as you are done with it

Then you can get newer records with:
sql = "Select * FROM [datadb] WHERE AutoIDdb>" & lMaxID & " ORDER BY AutoIDdb"
mrsdatadb.Open sql, mconAP, adOpenKeyset, adLockOptimistic, adCmdText

Or you can tell if there are new records with:

sql = "Select count(*) as NewerRecs FROM [datadb] where AutoIDdb>" & lMaxID
mrsdatadb.Open sql, mconAP, adOpenKeyset, adLockOptimistic, adCmdText
mrsdatadb.MoveFirst
If mrsdatadb("NewerRecs")>0 Then
    ' you have new data to handle
Else
    ' wait a litte while
End If

Essentially, you are trying to minimize your interaction with the data
to only the data you know you are going to need for the current
operation.  The data you fetch is only a snapshot, so anticipate that
it will begin changing the moment your code continues executing on the
next line.
Subject: Re: Connection to SQL with VB6
From: jstm-ga on 14 Mar 2005 19:01 PST
 
I all can say is thanks again.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy