473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

speeding up database access

Hi All,

I'm trying to figure out how I can speed up a fragment of code (which
has been converted from vb6 to .NET) that reads data from a database.
My knowledge on database programming is limited. The code uses DAO
(which, I understand, is no longer supported) - would there be any
performance benefit by converting to ADO.NET?

The code I'm attempting to speed up is below - are there any obvious
flaws which could be slowing it down?

Many thanks

Simon

myDB = DAODBEngine_definst.Workspaces(0).OpenDatabase(CDB Path &
TacCDBDB)

VMSQuery = myDB.CreateQueryDef("",
"SELECTtblPlanVmsSetting.strVmsId,tblPlanVmsSettin g.IntVmsType,tblVms.ysnFunctional"
& " FROM tblPlanVmsSetting INNER JOIN tblVms ON
tblPlanVmsSetting.strVmsId=tblVms.strVmsId" & " WHERE
tblPlanVmsSetting.strPlan=[Enter plan];")

DestQuery = myDB.CreateQueryDef("", "SELECT
tblVmsResponse.IntDestZone,(tblVmsResponse.LngDest inationDiversionNum)
as Diversionnumber," & " (tblVmsResponse.strIncidentLink) as
Incidentlink ,(tblVmsResponse.bytMessageResponse) as response,
tblVmsResponse.strPlan" & " FROM (tblIncidentResponse INNER JOIN
tblVmsResponse ON
tblIncidentResponse.strLinkNum=tblVmsResponse.strI ncidentLink) INNER
JOIN" & " tblPlanVmsSetting ON tblPlanVmsSetting.strVmsId
=tblVmsResponse.strVmsId" & " WHERE ((tblVmsResponse.strVmsId = [Enter
VMSID:]) AND (tblPlanVmsSetting.strPlan =[Enter PLANID:]) AND" & "
(tblPlanVmsSetting.strPlan=tblIncidentResponse.str Plan))" & " GROUP BY
tblVmsResponse.intDestZone,tblVmsResponse.LngDesti nationDiversionNum,"
& " tblVmsResponse.strIncidentLink,tblVmsResponse.bytM essageResponse,
tblVmsResponse.strPlan;")
PlanRS = myDB.OpenRecordset("tblPlan")
PlanRS.MoveLast()
PlanRS.MoveFirst()
PlanCounter = 0
Do While Not PlanRS.EOF
If PlanRS.Fields("ysnUseable").Value Then
If PlanRS.RecordCount > MaxPlans Then
Call fatal_error(CDBDB, "Controller",
"PlanManager.BuildPlanListFromCdb", "the number of plans exceeds the
maximum allowed (" & CStr(MaxPlans) & ")", "remove some plans", "")
Else
PlanCounter = PlanCounter + 1
Plan = New clsPlan
Plan.Counter = PlanCounter
Plan.ID = PlanRS.Fields("strPlan").Value
Plan.Issue = PlanRS.Fields("LngIssueNum").Value
Plan.Description = ""
If Not
IsDBNull(PlanRS.Fields("strDescription").Value) Then
Plan.Description =
PlanRS.Fields("strDescription").Value
End If
Plan.IsRunable = True

VMSQuery.Parameters("Enter plan").Value = Plan.ID

VMSRS = VMSQuery.OpenRecordset() 'Executes query
v = 0
Do While Not VMSRS.EOF
v = v + 1
If VMSRS.Fields("ysnFunctional").Value = False
Then
If (VMSRS.Fields("IntVmsType").Value = 1 Or
VMSRS.Fields("IntVmsType").Value = 2) Then
Plan.IsRunable = False
End If
Else

Call
Plan.AddVMSIndex(IntVMSNumForMOLAVMSID(VMSRS.Field s("strVmsId").Value))
End If

VMSRS.MoveNext()
Loop
VMSRS.Close()

'Now get the destination information
For v = 1 To Plan.VMSCount
DestQuery.Parameters("Enter VMSID:").Value =
MOLAVMSID(Plan.VMSIndex(v))
DestQuery.Parameters("Enter PLANID:").Value =
Plan.ID
DestRS = DestQuery.OpenRecordset() 'Executes
query
Do While Not DestRS.EOF
Div =
Divs.AddMOLA3Diversion(DestRS.Fields("diversionnum ber").Value)
Call Plan.AddMola3Destination(v,
DestRS.Fields("IncidentLink").Value, DestRS.Fields
("intDestZone").Value, DestRS.Fields("response").Value, Div,
DestRS.Fields("strPlan").Value)
Div = Nothing
DestRS.MoveNext()
Loop
DestRS.Close()
Next v
Plan.Finalise()
mCol.Add(Plan, Plan.ID)
Plan = Nothing
End If
End If
PlanRS.MoveNext()
Loop
PlanRS.Close()

Nov 21 '05 #1
2 1177
Just to prevent more times answer for the same question
Nov 21 '05 #2
The loop within a loop is going to make it slow. Every time you query a
database, it is a performance hit (think 1 sec). Querying a DB within a
loop will murder your performance for sure.
Also, I noticed a movefirst, movelast early-on in your code. That is an old
DAO technique usually used to determine your dataset size. I might skip
that because it causes DAO to traverse the entire result set.
I have also heard that adding optimizer hints to queries can sometimes work
against you if the DB is changed so that the hints are no longer valid. You
might want to look into that.
For sure, the query in a loop is going to be your biggest cpu eater.
Good luck

<si******@ntlworld.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi All,

I'm trying to figure out how I can speed up a fragment of code (which
has been converted from vb6 to .NET) that reads data from a database.
My knowledge on database programming is limited. The code uses DAO
(which, I understand, is no longer supported) - would there be any
performance benefit by converting to ADO.NET?

The code I'm attempting to speed up is below - are there any obvious
flaws which could be slowing it down?

Many thanks

Simon

...
PlanRS = myDB.OpenRecordset("tblPlan")
PlanRS.MoveLast()
PlanRS.MoveFirst()
PlanCounter = 0
Do While Not PlanRS.EOF .... VMSRS = VMSQuery.OpenRecordset() 'Executes query
v = 0
Do While Not VMSRS.EOF .... Call Plan.AddVMSIndex(IntVMSNumForMOLAVMSID(VMSRS.Field s("strVmsId").Value)) End If

VMSRS.MoveNext()
Loop
VMSRS.Close()

'Now get the destination information
For v = 1 To Plan.VMSCount
DestQuery.Parameters("Enter VMSID:").Value = MOLAVMSID(Plan.VMSIndex(v)) DestQuery.Parameters("Enter PLANID:").Value = Plan.ID DestRS = DestQuery.OpenRecordset() 'Executes query
Do While Not DestRS.EOF
Div = Divs.AddMOLA3Diversion(DestRS.Fields("diversionnum ber").Value) Call Plan.AddMola3Destination(v,
DestRS.Fields("IncidentLink").Value, DestRS.Fields
("intDestZone").Value, DestRS.Fields("response").Value, Div,
DestRS.Fields("strPlan").Value)
Div = Nothing
DestRS.MoveNext()
Loop
DestRS.Close()
Next v .... PlanRS.MoveNext()
Loop
PlanRS.Close()

Nov 21 '05 #3

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

Similar topics

6
by: Angel Faus | last post by:
Hi all, We've got an Oracle database in a Web application. Intermedia Text queries are an important part of the usage and work fine. The problem is that in order to generate a certain web...
3
by: Chris Ochs | last post by:
First of all, we are still running sapdb at the moment but are in the process of moving to postgresql, so it seemed a good idea to post this type of question here. In our environment we have...
8
by: Stephen K. Young | last post by:
If you have not seen it, this recent Microsoft Knowledge Base article is worth reading: http://support.microsoft.com/kb/889588 "How to optimize Office Access and Jet database engine...
2
by: Robert Wilkens | last post by:
Ok... This may be the wrong forum, but it's the first place I'm trying. I'm new to C# and just implemented the 3-tier Distributed application from Chapter 1 (the first walkthrough) in the...
5
by: Simon | last post by:
Hi All, I'm trying to figure out how I can speed up a fragment of code (which has been converted from vb6 to .NET) that reads data from a database. My knowledge on database programming is...
3
by: Mark Reed | last post by:
All, I have built a database recently which resides on a network server which is constantly being re-structured. This is something I have no control over so have had to incorporate a means by...
3
by: Cleverbum | last post by:
I was hoping to parse a webpage and extract all link and image URLs from it and enter the new ones into mySQL tables, below is my code to do it, I've tried to optimise it as much as I can but it...
5
by: RobinAG | last post by:
Hello, I just split my database into front and back end. My front end users are experiencing really slow opening of forms. I've searched online for help speeding up forms, but I'm not sure what...
10
by: ags5406 | last post by:
I've created an application that downloads data daily from a secure web site and stores that data in an Access database. Then there are different options for allowing the user to do keyword and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.