473,804 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO parameters queries and stored procedures - and Connections

I use the following code to retrieve to recordsets into two local tables,
from an mdb file over a WAN. Works fine, but I'm trying to tweak the speed,
and I have some questions:

1. I tried both an ADOX-created stored procedure and a regular Access
parameter query. After several tests, I came to the conclusion that there
was no statistcal difference between the two. Does this make sense, or
could I do something different to speed it up (the two queries are just
standard three-table joined Select queries with one parameter)?

2. When I wrap the two calls below in a third recordset, opened on the user
table, this speeds things up - in other words, when the recordset 'rs' is
closed and re-opened, the connection to the WAN mdb is lost, and has to be
re-established - which is noticeable over the WAN. Is there any other way
to keep the connection open ... and why does closing the recordset close it?

3. Any other suggestions?
-----------------------------------------------------------
Dim cnxn As ADODB.Connectio n
Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim prm1 As ADODB.Parameter
Dim cmd1 As ADODB.Command
Set rs = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set cnxn = New ADODB.Connectio n
Set cmd1 = New ADODB.Command

cnxn.Provider = "Microsoft.Jet. OLEDB.4.0"
cnxn.Open "Data Source=" & GetServer()

Set prm1 = cmd1.CreatePara meter("PO", adVarChar, adParamInput,
Len(GetSelected PO()))
prm1.Value = GetSelectedPO()
With cmd1
.ActiveConnecti on = cnxn
.CommandText = "HomeInvestigat ionPQuery"
.CommandType = adCmdStoredProc
.Parameters.App end prm1
End With

rs2.Open "HomeInvestigat ionTable", CurrentProject. Connection, adOpenKeyset,
adLockOptimisti c, adCmdTable
With rs
.Open cmd1, , adOpenForwardOn ly, adLockReadOnly, adCmdStoredProc
Do While Not .EOF
rs2.AddNew
For f = 0 To 5
rs2.Fields(f) = .Fields(f)
Next f
rs2.Update
.MoveNext
Loop
.Close
rs2.Close

rs2.Open "HomeCaseloadTa ble", CurrentProject. Connection,
adOpenKeyset, adLockOptimisti c, adCmdTable
cmd1.CommandTex t = "HomeCaseloadPQ uery"
.Open cmd1, , adOpenForwardOn ly, adLockReadOnly, adCmdStoredProc
Do While Not .EOF
rs2.AddNew
For f = 0 To 2
rs2.Fields(f) = .Fields(f)
Next f
rs2.Update
.MoveNext
Loop
.Close
End With
rs2.Close
cnxn.Close
Set cmd1 = Nothing
Set prm1 = Nothing
--
Darryl Kerkeslager

Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.
See www.adcritic.com/interactive/view.php?id=5927
Nov 13 '05 #1
20 2654
Do you really have to use recordsets? Can you just use two Update
Queries?

If recordsets then ...
Quite often when dealing with ADODB recordsets it's more efficient and
faster to open them, disconnect them (Set .ActiveConnecti on = Nothing),
do our work, reconnect them (Set .ActiveConnecti on =
YourConnectionO bject) and do a batch update. TTBOMK the batch update is
asynchronous, so we can go about doing something else while it does its
work.

It's unnecessary to close and release ADO object pointers.

Nov 13 '05 #2
On 25 Jul 2005 19:09:51 -0700, "lylefair" <ly******@yahoo .ca> wrote:
Do you really have to use recordsets? Can you just use two Update
Queries?

If recordsets then ...
Quite often when dealing with ADODB recordsets it's more efficient and
faster to open them, disconnect them (Set .ActiveConnecti on = Nothing),
do our work, reconnect them (Set .ActiveConnecti on =
YourConnection Object) and do a batch update. TTBOMK the batch update is
asynchronous , so we can go about doing something else while it does its
work.

It's unnecessary to close and release ADO object pointers.


Actually, if you open the recordset as static, batch optimistic, there's no
benefit to disconnecting it. It's not going to talk to the database again
until you do the batch update, disconnected or not. The only reason to
disconnect is if you really do want to close the connection to conserver
resources.
Nov 13 '05 #3
Lyle Fairfield wrote:
Do you really have to use recordsets? Can you just use two Update
Queries?
Good question. I would be updating the Front End mdb from the Back End mdb,
which I have never done before. How would I do this? Wouldn't the BE have
to know where the FE is?
If recordsets then ...
Quite often when dealing with ADODB recordsets it's more efficient and
faster to open them, disconnect them (Set .ActiveConnecti on = Nothing),
do our work, reconnect them (Set .ActiveConnecti on =
YourConnectionO bject) and do a batch update.
So change this ...

rs2.Open "HomeInvestigat ionTable", CurrentProject. Connection, adOpenKeyset,
adLockOptimisti c, adCmdTable

With rs
.Open cmd1, , adOpenForwardOn ly, adLockReadOnly, adCmdStoredProc

Do While Not .EOF
rs2.AddNew
For f = 0 To 5
rs2.Fields(f) = .Fields(f)
Next f
rs2.Update
.MoveNext
Loop

.... to this? ..

rs2.Open "HomeInvestigat ionTable", CurrentProject. Connection, adOpenKeyset,
adLockBatchOpti mistic, adCmdTable

With rs
.Open cmd1, , adOpenForwardOn ly, adLockReadOnly, adCmdStoredProc

Set .ActiveConnecti on = Nothing
Do While Not .EOF
rs2.AddNew
For f = 0 To 5
rs2.Fields(f) = .Fields(f)
Next f
.MoveNext
Loop
Set .ActiveConnecti on = cnxn
rs2.UpdateBatch

It's unnecessary to close and release ADO object pointers.


I've stopped doing it for recordsets, but I wasn't sure the same applied for
command and parameter objects.


Darryl Kerkeslager

Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.
See www.adcritic.com/interactive/view.php?id=5927
Nov 13 '05 #4
Steve Jorgensen wrote:
The only reason to
disconnect is if you really do want to close the connection to conserver
resources.


I'm doing this over a WAN (The Powers said I couldn't use their SQL Server).
All I want to accomplish is make it faster, any way I can. The WAN is good
and fast, and the PCs and server involved are first rate. I just want to:

1. Not open and close the connection if preventable - this alone takes
anywhere from 1-2 seconds, so if I open and close a recordset 4 times
instead of 1 in one Save action, that's an extra 3-6 seconds I add.

2. Not send any more data TO the server than I need to to GET data.
--
Darryl Kerkeslager

Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.
See www.adcritic.com/interactive/view.php?id=5927
Nov 13 '05 #5
On Mon, 25 Jul 2005 22:58:02 -0400, "Darryl Kerkeslager"
<ke*********@co mcast.net> wrote:
Steve Jorgensen wrote:
The only reason to
disconnect is if you really do want to close the connection to conserve
resources.


I'm doing this over a WAN (The Powers said I couldn't use their SQL Server).
All I want to accomplish is make it faster, any way I can. The WAN is good
and fast, and the PCs and server involved are first rate. I just want to:

1. Not open and close the connection if preventable - this alone takes
anywhere from 1-2 seconds, so if I open and close a recordset 4 times
instead of 1 in one Save action, that's an extra 3-6 seconds I add.

2. Not send any more data TO the server than I need to to GET data.


I didn't realize you were using an Access MDB over a WAN. That's generally
both slow and unreliable. Can you get set up to remote control your PC at
work via Terminal Services? Alternatively, if there are only a handfull of
simultaneous users, could you use MSDE on your computer, and access that over
the WAN?

If none of those is an option, perhaps, you should look into replication.
David Fenton may have some advice on this point.
Nov 13 '05 #6
A few more things

Steve points out that it's unnecessary to close the connection, if one
changes the cursor type to adOpenStatic.

You should still be able to use
Dim FieldArray As Variant
FieldArray = Array(0, 1, 2, 3, 4, 5)
rs2.Open "HomeInvestigat ionTable", CurrentProject. Connection,
adOpenStatic,
adLockBatchOpti mistic, adCmdTable
With rs
.Open cmd1, , adOpenForwardOn ly, adLockReadOnly, adCmdStoredProc
Do While Not .EOF
rs2.AddNew FieldArray, Array(Fields(0) , Fields(1), Fields(2),
Fields(3), Fields(4), Fields(5))
.MoveNext
Loop
End With
rs2.UpdateBatch
(with lines inserted in the correct areas)
To avoid iterating f

CurrentProject. Connection can be 100s of times slower than a simple ADO
connection. You might try creating an independent connection (naming
the provider, data source, etc.)

Finally, running Access code can sometimes be very slow. In your
routine there is nothing that I can see that requires Access. I'm going
to guess that running this as VB Script, or Compiled VB, or JScript in
the Wsh environment might be faster.

Finally, finally, if the connection can find these tables in the front
end and backend, then why not SQL? In SQL we can reference a table or
query in an mdb with the path to the table and the dot and the name of
the object, perhaps all enclosed with [...].
eg
With DBEngine(0)(0)
.Execute "DELETE * FROM [C:\Documents and Settings\Lyle
Fairfield\My Documents\Acces s\terrawaretabl es.mdb].[transactions]"
.Execute "INSERT INTO " _
& "[C:\Documents and Settings\Lyle Fairfield\My
Documents\Acces s\terrawaretabl es2.mdb].[transactions] " _
& "SELECT * FROM [C:\Documents and Settings\Lyle Fairfield\My
Documents\Acces s\terrawaretabl es.mdb].[transactions] "
End With

Nov 13 '05 #7
Steve Jorgensen <no****@nospam. nospam> wrote in
news:to******** *************** *********@4ax.c om:
I didn't realize you were using an Access MDB over a WAN. That's
generally both slow and unreliable. Can you get set up to remote
control your PC at work via Terminal Services? Alternatively, if
there are only a handfull of simultaneous users, could you use
MSDE on your computer, and access that over the WAN?

If none of those is an option, perhaps, you should look into
replication. David Fenton may have some advice on this point.


Well, there's WANs and then there's WANs. One client of mine, a
school district in New Jersey, has a WAN connecting all the schools,
but it runs at Gigabit speeds, so it's faster than most LANs, and
thus perfectly appropriate for using Access MDBs. And, indeed, the
first app I redesigned for them is indeed being run with the data
MDB on the high school server, and the end users both at the high
school and out in the grade schools and middle schools, on the other
side of the WAN.

So, the real problem with WANs is when they are running at under
10BaseT speed.

Oh, also, wireless is unacceptable, too.

Replication is not for the faint of heart, and I would say not at
all preferable to WTS except where WTS can't be done.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
> I didn't realize you were using an Access MDB over a WAN. That's
generally
both slow and unreliable.
Slow, yes, unreliable, no.
Can you get set up to remote control your PC at
work via Terminal Services? Alternatively, if there are only a handful of
simultaneous users, could you use MSDE on your computer, and access that
over
the WAN?
80 users - ?? simultaneous (perhaps 20) - so MSDE is out. But MSDE,
Terminal Services, even scripting are all out for the same reason - I'm not
IT staff, and nothing will be put in without the approval of IT staff -
which will not come. I lost my automatic backups when IT nixed scripts run
from anywhere but the servers, and I was forced to put this on the WAN when
they eliminated all file sharing. As of now, I can't even share out my
Outlook calendar.

With either IBM or Northrop Grumman getting the IT outsourcing contract
soon, there will be no positive changes for me. I'm resigned to this
solution for the next 18 months until the enterprise .Net application is
installed, making my app obsolete.
If none of those is an option, perhaps, you should look into replication.
David Fenton may have some advice on this point.


Well, my subject line contains the text "ADO", so David has doubtless
blocked the thread ;), but I will read the chapter on replication in the ADH
and ask as needed.
--
Darryl Kerkeslager

Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.

See www.adcritic.com/interactive/view.php?id=5927
Steve Jorgensen wrote:

Nov 13 '05 #9
Lyle Fairfield wrote:

A few more things

Steve points out that it's unnecessary to close the connection, if one
changes the cursor type to adOpenStatic.

You should still be able to use
Dim FieldArray As Variant
FieldArray = Array(0, 1, 2, 3, 4, 5)
rs2.Open "HomeInvestigat ionTable", CurrentProject. Connection,
adOpenStatic,
adLockBatchOpti mistic, adCmdTable
With rs
.Open cmd1, , adOpenForwardOn ly, adLockReadOnly, adCmdStoredProc
Do While Not .EOF
rs2.AddNew FieldArray, Array(Fields(0) , Fields(1), Fields(2),
Fields(3), Fields(4), Fields(5))
.MoveNext
Loop
End With
rs2.UpdateBatch
(with lines inserted in the correct areas)
To avoid iterating f
Thank you - I couldn't figure out a method to avoid that, even though I knew
it would be a drag.

CurrentProject. Connection can be 100s of times slower than a simple ADO
connection. You might try creating an independent connection (naming
the provider, data source, etc.)
I only use the CurrentProject. Connection for the local mdb, and specify the
path for the WAN mdb. But I'll try specifying both, as I really need to
wring out every drop of performance.

Finally, running Access code can sometimes be very slow. In your
routine there is nothing that I can see that requires Access. I'm going
to guess that running this as VB Script, or Compiled VB, or JScript in
the Wsh environment might be faster.
Unfortunately scripting has been disabled from local PCs along with other
security features.
Finally, finally, if the connection can find these tables in the front
end and backend, then why not SQL? In SQL we can reference a table or
query in an mdb with the path to the table and the dot and the name of
the object, perhaps all enclosed with [...]. .Execute "DELETE * FROM [C:\Documents and Settings\Lyle
Fairfield\My Documents\Acces s\terrawaretabl es.mdb].[transactions]"
.Execute "INSERT INTO " _
& "[C:\Documents and Settings\Lyle Fairfield\My
Documents\Acces s\terrawaretabl es2.mdb].[transactions] " _
& "SELECT * FROM [C:\Documents and Settings\Lyle Fairfield\My
Documents\Acces s\terrawaretabl es.mdb].[transactions] "
End With


Ahhh! I really didn't know that you could do that (probably should have,
but didn't). Yes, I would love it if I could stick with a(n) SQL solution.

Thank you both, Steve and Lyle.

Now to test out my newfound nowledge ...
--
Darryl Kerkeslager

Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.

See www.adcritic.com/interactive/view.php?id=5927
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
15235
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental differences between a view and a query, or rather, when it is more appropriate to use one vs. the other. It seems to me that most select queries can be implemented as views, and I can't see the downside to doing so.
3
16949
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
1
2092
by: zlatko | last post by:
I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are stored procedures with input parameters by which they filter rows to be updated or inserted into other tables. Filtration is based on certain actual values on forms (form with several subforms). My question is following: How to pass parameters to those stored procedures that are triggered by a button?...
2
17361
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures (update, append) should be activated in order to transfer data to other tables. I tried to avoid any coding in VB, as I am not a professional, but I have found a statement in an article, that, unlike select queries, form's Input Property can't be...
14
3434
by: | last post by:
Hi, I was performing SQL UPDATE queries and I notice that they SUCCEED on the ExecuteNonQuery() call with NO exceptions raised BUT they fail at the Database. They say they succeed in the code but they fail at the database. To fix this they Parameters.Add must be called in the ORDER they are in the SQL STATEMENT. This is confusing and bad.
3
2145
by: Zlatko | last post by:
A question concerning Access Project with SQL Server: I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are stored procedures with input parameters by which they filter rows to be updated or inserted into other tables. Filtration is based on certain actual values on forms (form with several subforms). My question is following: How to pass parameters to...
7
21643
by: Zlatko Matiæ | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
5
2363
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored Procedures with a data reader to add various parameters. However, if I have a stored procedure such as CREATE usp_SelectfromJobNumbers (@par1 datatype, @par2 datatype, @par3 datatype)
9
377
by: Bill E. | last post by:
I'm creating an MS Access application that connects to a SQL Server 2005 database using pass-through queries and ADO to call stored procedures. I ran a SQL trace and started clicking through various forms to look at how things were being handled on the database. I noticed an alarming number of connections were opened as if there was absolutely no connection pooling. After several clicks I had 20 new connections. It appeared that a new...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.