Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 January 13th, 2006, 11:42 PM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Prepared SQL VS. Regular Queries

Guys,

I tried to write a prepared sql script instead of just executing queries inside of a loop. I timed it, and the prepared script runs over a minute slower than the regular script. I don't understand why it would take longer. I was expecting to save some time.

Here is the prepared statement script:

Dim con As New ADODB.Connection
Dim com As New ADODB.Command
Dim strqry As String

con.ConnectionString = CurrentProject.Connection
con.CursorLocation = adUseServer
con.Mode = adModeReadWrite
con.Open

Dim rsData As ADODB.Recordset
Set rsData = New ADODB.Recordset
rsData.ActiveConnection = CurrentProject.Connection
rsData.CursorType = adOpenKeyset

strqry = " select q33_1 from test "
         rsData.Open (strqry)

Dim SQL_TO_USE As String
SQL_TO_USE = "update test set zip = 'TestThisString' where q33_1 = ?"

com.CommandType = adCmdText
com.Prepared = True
com.CommandText = SQL_TO_USE
com.Parameters.Append com.CreateParameter("value", adVarChar, adParamInput, 50)
Set com.ActiveConnection = con

While Not rsData.EOF
   com("value") = rsData("q33_1")
   com.Execute
   rsData.MoveNext
Wend

con.Close


Here is the regular way of doing it:

Dim strqry As String
Dim rsData As ADODB.Recordset
Set rsData = New ADODB.Recordset
rsData.ActiveConnection = CurrentProject.Connection
rsData.CursorType = adOpenKeyset

strqry = " select q33_1 from test "
         rsData.Open (strqry)

Dim rsAction As ADODB.Recordset
Set rsAction = New ADODB.Recordset
rsAction.ActiveConnection = CurrentProject.Connection

While Not rsData.EOF
   strqry = "update test set zip = 'RegularTest' where q33_1 = " & rsData("q33_1") & ""
   rsAction.Open (strqry)

   rsData.MoveNext
Wend

Any suggestions would be greatly appreciated.

nikotromus
__________________
nikotromus
 
Old January 14th, 2006, 02:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Is this an ADP talking to SQL Server? This isn't real clear:

con.ConnectionString = CurrentProject.Connection
con.CursorLocation = adUseServer
con.Mode = adModeReadWrite
con.Open

It looks like you're attempting to open a connection other than the ADO connection already in use by Access. Havn't seen CurrentProject.Connection assigned as a connection string value before. Its already the open ADO connection that Access is using.

Maybe to start:

Set com.ActiveConnection = CurrentProject.Connection

instead of

Set com.ActiveConnection = con

Then at least you're comparing apples to apples.

Bob

 
Old January 14th, 2006, 06:56 PM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bob, I tried it. I took out every reference to the con object and instead made the connection through the command Set com.ActiveConnection = CurrentProject.Connection.

It worked but there was no difference in speed. The prepared scrips still runs one minute slower than executing the non-parsed query script. Oh well. I think this one will just remain a mistery.


nikotromus





Similar Threads
Thread Thread Starter Forum Replies Last Post
Prepared SQL VS. Regular Queries nikotromus Beginning VB 6 1 June 24th, 2006 10:08 AM
Prepared SQL VS. Regular Queries nikotromus Pro VB 6 0 January 17th, 2006 08:37 PM
Prepared SQL VS. Regular Queries nikotromus Pro VB Databases 0 January 17th, 2006 08:35 PM
Anyone Expert in SQL Queries? itHighway HTML Code Clinic 3 June 3rd, 2005 09:57 AM
Anyone Expert in SQL Queries itHighway Classic ASP Basics 2 May 24th, 2005 03:37 AM





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