Page 1 of 2 12 LastLast
Results 1 to 40 of 51

Thread: records retreive extremely slow

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    records retreive extremely slow

    hello,i have problem with running really slow when it is retreaving records from table to display only the records I need. I am using access (.mdb) for my database and I use ADO to connect to the database on visual basic .most of the time my computer will hang when i retreaving data and my computer will become extremely slow until i need to restart computer.Does anyone know how to go about making data retreaval more efficient or faster, either through tweaking my code or tweaking the db itself using MS Access ?please help Thanks!


    VB Code:
    1. Private m_rs As ADODB.Recordset  ' Recordset tool
    2.  
    3. Private Sub CmdAdd_Click(Index As Integer)
    4.     On Error Resume Next
    5.     With m_rs
    6.         .Fields("Location") = ComboLocation.Text
    7.         .Fields("DatePurchase") = DTPpurchase
    8.         .Fields("Item") = ComboItem.Text
    9.         .Fields("Detail") = Txtitem2.Text
    10.         .Fields("IDNumber") = Txtidnumber.Text
    11.         .Fields("Price") = Txtprice.Text
    12.         .Fields("Status") = Combostatus.Text
    13.         .Fields("DateScrap") = DTPScrap
    14.         .Update
    15.         Call clear
    16.         MsgBox "Record Saved", vbInformation, "Record is Saved"
    17.         'End If
    18.     End With
    19. End Sub
    20. 'Delete Record
    21. Private Sub cmddelete_Click(Index As Integer)
    22.     On Error Resume Next
    23.     With m_rs
    24.         .Fields("Location") = ComboLocation.Text
    25.         .Fields("DatePurchase") = DTPpurchase
    26.         .Fields("Item") = ComboItem.Text
    27.         .Fields("Detail") = Txtitem2.Text
    28.         .Fields("IDNumber") = Txtidnumber.Text
    29.         .Fields("Price") = Txtprice.Text
    30.         .Fields("Status") = Combostatus.Text
    31.         .Fields("DateScrap") = DTPScrap
    32.         .Fields("Deletedate") = Txtdeldate.Text
    33.         Call clear
    34.         If MsgBox("Are you sure you wan't to delete record", vbOKCancel + vbExclamation, "Deleting Record") = vbOK Then
    35.             .Update
    36.             Call display1
    37.         End If
    38.     End With
    39. End Sub
    40.  
    41. Private Sub Cmdnew_Click(Index As Integer)
    42.     On Error Resume Next
    43.     Call clear
    44.     m_rs.AddNew
    45.     Txtlocation.SetFocus
    46.  
    47. End Sub
    48. Private Sub ComboItem_Click()
    49. Dim imageName As String
    50.     Picture1.Picture = LoadPicture()
    51.     imageName = "D:\Tool Inventory v8.6\photo\" & ComboItem.Text & ".jpg"
    52.     If Dir$(imageName) <> "" Then
    53.         Picture1.Picture = LoadPicture(imageName)
    54.     Else
    55.         Picture1.Picture = LoadPicture()
    56.     End If
    57. End Sub
    58.  
    59. Private Sub Datagrid1_Click()
    60.  Dim imageName As String
    61.      DataGrid1.SetFocus
    62.     DataGrid1.MarqueeStyle = dbgHighlightRow
    63.     If Len(DataGrid1.Columns(1)) = 0 Then
    64.         DTPpurchase.Enabled = False
    65.     Else
    66.         DTPpurchase.Enabled = True
    67.         DTPpurchase.Value = DataGrid1.Columns(1)
    68.     End If
    69.     If Len(DataGrid1.Columns(7)) = 0 Then
    70.         DTPScrap.Enabled = False
    71.     Else
    72.         DTPScrap.Enabled = True
    73.         DTPScrap.Value = DataGrid1.Columns(7)
    74.     End If
    75.     ComboLocation.Text = DataGrid1.Columns(0)
    76.     ComboItem.Text = DataGrid1.Columns(2)
    77.     Txtitem2.Text = DataGrid1.Columns(3)
    78.     Txtidnumber.Text = DataGrid1.Columns(4)
    79.     Txtprice.Text = DataGrid1.Columns(5)
    80.     Combostatus.Text = DataGrid1.Columns(6)
    81.     DataGrid1.Refresh
    82.    
    83.     Picture1.Picture = LoadPicture()
    84.     imageName = App.Path & "\photo\" & ComboItem.Text & ".jpg"
    85.     If Dir$(imageName) <> "" Then
    86.         Picture1.Picture = LoadPicture(imageName)
    87.     Else
    88.         Picture1.Picture = LoadPicture()
    89.     End If
    90.  
    91. End Sub
    92. Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    93. 'row down
    94.   Dim imageName As String
    95.      DataGrid1.SetFocus
    96.     DataGrid1.MarqueeStyle = dbgHighlightRow
    97.     If Len(DataGrid1.Columns(1)) = 0 Then
    98.         DTPpurchase.Enabled = False
    99.     Else
    100.         DTPpurchase.Enabled = True
    101.         DTPpurchase.Value = DataGrid1.Columns(1)
    102.     End If
    103.     If Len(DataGrid1.Columns(7)) = 0 Then
    104.         DTPScrap.Enabled = False
    105.     Else
    106.         DTPScrap.Enabled = True
    107.         DTPScrap.Value = DataGrid1.Columns(7)
    108.     End If
    109.     ComboLocation.Text = DataGrid1.Columns(0)
    110.     ComboItem.Text = DataGrid1.Columns(2)
    111.     Txtitem2.Text = DataGrid1.Columns(3)
    112.     Txtidnumber.Text = DataGrid1.Columns(4)
    113.     Txtprice.Text = DataGrid1.Columns(5)
    114.     Combostatus.Text = DataGrid1.Columns(6)
    115.     DataGrid1.Refresh
    116.    
    117.     Picture1.Picture = LoadPicture()
    118.     imageName = App.Path & "\photo\" & ComboItem.Text & ".jpg"
    119.     If Dir$(imageName) <> "" Then
    120.         Picture1.Picture = LoadPicture(imageName)
    121.     Else
    122.         Picture1.Picture = LoadPicture()
    123.     End If
    124.  
    125.  
    126. End Sub
    127. Private Sub Form_Load()
    128.     Dim rs1 As ADODB.Recordset
    129.     Dim rs2 As ADODB.Recordset
    130.  
    131.     'sql query login user department
    132.    Set m_rs = OpenRecordset("select * from [Inventory]" & vbCrLf & _
    133.                             "where ([Location] in (" & vbCrLf & _
    134.                             "  select [DepartmentName] from [Department]" & vbCrLf & _
    135.                             "  where [Id] in (" & vbCrLf & _
    136.                             "    select [DepartmentID] from [UserDepartment]" & vbCrLf & _
    137.                             "    where [UserId] = '" & gUserId & "'" & vbCrLf & _
    138.                             "  )" & vbCrLf & _
    139.                             ") or exists(SELECT * FROM UserRoles WHERE [UserId] = " & gUserId & _
    140.                             " and [RoleId] in (select [Id] from [Roles] where [RoleName] = 'admin')))" & _
    141.                             " and Deletedate is null", adOpenStatic, adLockOptimistic)
    142.     Set DataGrid1.DataSource = m_rs
    143.     Debug.Print "Connection Object Created"
    144.    
    145.     'stutus list
    146.     Combostatus.AddItem "Active"
    147.     Combostatus.AddItem "Relocate"
    148.     Combostatus.AddItem "Spoilt"
    149.    
    150. 'If Not IsNull(m_rs!Location) Then
    151.  ' ComboLocation.Text = m_rs!Location
    152. 'End If
    153.  
    154. 'If Not IsNull(m_rs!Item) Then
    155.  ' ComboItem.Text = m_rs!Item
    156. 'End If
    157.  
    158. Set rs1 = OpenRecordset("select distinct Location From Inventory", adOpenStatic, adLockReadOnly)
    159.    While Not rs1.EOF
    160.             ComboLocation.AddItem rs1!Location
    161.             rs1.MoveNext
    162.         Wend
    163.         rs1.Close
    164. Set rs1 = Nothing
    165.  
    166. Set rs2 = OpenRecordset("select distinct Item From Inventory", adOpenStatic, adLockReadOnly)
    167.    While Not rs2.EOF
    168.             ComboItem.AddItem rs2!Item
    169.             rs2.MoveNext
    170.         Wend
    171.         rs2.Close
    172. Set rs2 = Nothing
    173.    
    174.     'Text1.Text = "Database Record " & "_" & m_rs.RecordCount
    175.     Txtdeldate.Text = Format(Now, "dd/mm/yyyy")
    176. End Sub
    177.  
    178. Private Sub CmdExit_Click()
    179.     Unload Me
    180. End Sub
    181. Private Sub cmdSave_Click()
    182.     ' This button will save the changes and additions
    183.     With m_rs
    184.         ' If our Textboxes not empty
    185.         If Txtlocation.Text <> "" And Txtdateofpurchase.Text <> "" _
    186.                 And Txtitem1.Text <> "" And Txtitem2.Text And Txidnumber.Text <> "" _
    187.                 And Txtprice.Text <> "" And Txstatus.Text <> "" And Txtdateofscrap.Text Then
    188.             ' Put the content of our textboxes in the current
    189.             ' recordset
    190.             .Fields("Location") = ComboLocation.Text
    191.             .Fields("Date Of Purchase") = Txtdateofpurchase.Text
    192.             .Fields("Item") = ComboItem.Text
    193.             .Fields("Detail") = Txtitem2.Text
    194.             .Fields("ID Number") = Txtidnumber.Text
    195.             .Fields("Price") = Txtprice.Text
    196.             .Fields("Status") = Txtstatus.Text
    197.             .Fields("Date Of Scrap") = Txtdateofscrap.Text
    198.             .Update
    199.         End If
    200.     End With
    201.     ' Ready, now we're able to change our data
    202. End Sub

  2. #2
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: records retreive extremely slow

    How many records are you trying to retrieve?

    When doing a Select query, specify the field name not *. Well, in some case you need to and try to avoid using On Error Resume Next if necessary. It will be easier to debug.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    zynder:
    The records is about 6000.

  4. #4
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: records retreive extremely slow

    Try changing this

    VB Code:
    1. With m_rs
    2.         .Fields("Location") = ComboLocation.Text
    3.         .Fields("DatePurchase") = DTPpurchase
    4.         .Fields("Item") = ComboItem.Text
    5.         .Fields("Detail") = Txtitem2.Text
    6.         .Fields("IDNumber") = Txtidnumber.Text
    7.         .Fields("Price") = Txtprice.Text
    8.         .Fields("Status") = Combostatus.Text
    9.         .Fields("DateScrap") = DTPScrap
    10.         .Update
    11. End With

    to this

    VB Code:
    1. With m_rs
    2.         .Fields("Location").Value = ComboLocation.Text
    3.         .Fields("DatePurchase").Value = DTPpurchase
    4.         .Fields("Item").Value = ComboItem.Text
    5.         .Fields("Detail").Value = Txtitem2.Text
    6.         .Fields("IDNumber").Value = Txtidnumber.Text
    7.         .Fields("Price").Value = Txtprice.Text
    8.         .Fields("Status").Value = Combostatus.Text
    9.         .Fields("DateScrap").Value = DTPScrap
    10.         .Update
    11. End With

    Then add some doevents while populating your controls.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    zynder:
    not much improve for the retreive speed.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: records retreive extremely slow

    As a side note, I'd ditch those 'On Error Resume Next' statements in the Add and Delete Subs. You aren't doing anything that should cause you to have to Resume next per se (use On Error Goto xxxx).

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    bruce fox:
    i has try your method to use 'On Error Resume Next' statements in the Add and Delete Subs.but the problem still remind the same...extremely slow until computer and need to reboot agian.

  8. #8
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: records retreive extremely slow

    Ok here's what you need to do. Remove all On Error Resume Next and see if there's an error.

    If there is, then post the offending line of code. In my opinion, there must be an error on your coding but since you have that Resume Next, chances are you won't find the error and be impossible to debugged.

    If they're properly coded, even if you load more than 6,000 records say 30k plus, it'll not get to the point of system freeze. There must be something in there that you can't find.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    zynder:
    i has try to remove all the "on error resume next",but the problem is still remain the same. what can i do now?please help.Thanks!

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: records retreive extremely slow

    if you run your program continuously does it just get slower? or is it if you keep restarting it?

    do you have code in your form unload or form query unload events?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    westconn1:
    once i run project to retrieve record my computer will get extremely slow until hang for few sec and i need to reboot agian to gain back to normal speed.ya ,from database have database query events.

  12. #12
    Addicted Member
    Join Date
    Mar 2006
    Posts
    178

    Re: records retreive extremely slow

    Is the database on your pc or on a network? If it's on a network can you copy it to your pc and see if your program runs faster?

    I've heard DAO is faster than ADO, I use DAO but that's just my preference.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    davidbishton:
    the database is on my pc and i using ADO.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: records retreive extremely slow

    Thread moved to correct forum.

    As already mentioned above, specify your fields (instead of "Select *"), do not use "On Error Resume Next" (unless you have a good reason - which you certainly dont), and specify properties when working with objects (such as .Value for fields, and possibly for your date pickers too).


    There are further improvements that can be made to the speed of your SQL statement, but we need to clean up your coding issues a bit first.


    What is OpenRecordset? Presumably this is a function which you have written, and not shown.

    What is gUserId? Presumably a global variable, but has it been set appropriately before the form loads? (note that in your main SQL statement, you dont have ' around it for the UserRoles part)

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    si_the_geek:
    you are right the OpenRecordset written are not shown. gUserId is Id from database users table Id.At module1 you can see all the variable there.please guide i'm new in VB.Thanks!

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: records retreive extremely slow

    We need to see the code for OpenRecordset, and how you get gUserID (is it set before this form loads?).

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    si_the_geek:
    this is the code for OpenRecordset:
    VB Code:
    1. Public Function OpenRecordset(ByVal strsql As String, _
    2.         Optional ByVal CursorType As CursorTypeEnum = CursorTypeEnum.adOpenForwardOnly, _
    3.         Optional ByVal LockType As LockTypeEnum = LockTypeEnum.adLockReadOnly) As Recordset
    4.     Dim rs As New Recordset
    5.     If OpenConn Then 'aviod time ping out
    6.         On Error GoTo TrackErr
    7.         rs.Open strsql, conn, CursorType, LockType
    8.     End If
    9.     Set OpenRecordset = rs
    10.     Exit Function
    11. TrackErr:
    12.     gErrDescription = Err.Description
    13.     Err.clear
    14. End Function

    gUserID is get before this form loads at modules->module1.

    This is Module1 code.Is load before the previous code i post.
    VB Code:
    1. Option Explicit
    2.  
    3. Public gErrDescription As String 'error message
    4. Public gLogined As Boolean 'success login ?
    5. Public gLoginName As String 'login name
    6. Public gUserId As String 'login user id
    7. Public gUsreName As String ' login user name
    8. Public conn As Connection
    9.  
    10. 'begin code
    11. Public Sub Main()
    12.     gLogined = False 'not yet login
    13.     frmLogin.Show vbModal 'display login form
    14.     If Not gLogined Then End    'login fail will end login screen
    15.     frmMain.Show      'login success will load frmMain
    16. End Sub
    17.  
    18. 'connect database table
    19. Private Function OpenConn() As Boolean
    20.     If conn Is Nothing Then Set conn = New Connection
    21.     With conn
    22.         If .State = adStateClosed Then
    23.             .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _
    24.                 "\Tool.mdb;Persist Security Info=False"
    25.             .CursorLocation = adUseClient
    26.             On Error GoTo TrackErr
    27.             .Open
    28.         End If
    29.         OpenConn = (.State = adStateOpen)
    30.     End With
    31.     Exit Function
    32. TrackErr:
    33.     gErrDescription = Err.Description
    34.     Err.clear
    35. End Function
    36.  
    37. Public Function ExecSql(ByVal strsql As String) As Boolean
    38.     If OpenConn Then 'aviod time ping out
    39.         On Error GoTo TrackErr
    40.         conn.Execute strsql
    41.         ExecSql = True
    42.     End If
    43.     Exit Function
    44. TrackErr:
    45.     gErrDescription = Err.Description
    46.     Err.clear
    47. End Function
    48.  
    49. Public Function QuerySql(ByVal strsql As String) As Recordset
    50.     If OpenConn Then 'aviod time ping out
    51.         On Error GoTo TrackErr
    52.         Set QuerySql = conn.Execute(strsql)
    53.     End If
    54.     Exit Function
    55. TrackErr:
    56.     gErrDescription = Err.Description
    57.     Err.clear
    58. End Function
    59.  
    60. Public Function OpenRecordset(ByVal strsql As String, _
    61.         Optional ByVal CursorType As CursorTypeEnum = CursorTypeEnum.adOpenForwardOnly, _
    62.         Optional ByVal LockType As LockTypeEnum = LockTypeEnum.adLockReadOnly) As Recordset
    63.     Dim rs As New Recordset
    64.     If OpenConn Then 'aviod time ping out
    65.         On Error GoTo TrackErr
    66.         rs.Open strsql, conn, CursorType, LockType
    67.     End If
    68.     Set OpenRecordset = rs
    69.     Exit Function
    70. TrackErr:
    71.     gErrDescription = Err.Description
    72.     Err.clear
    73. End Function
    74.  
    75. 'close table connection
    76. Public Sub CloseConn()
    77.     If conn Is Nothing Then Exit Sub
    78.     If conn.State = adStateClosed Then Exit Sub
    79.     conn.Close
    80.     Set conn = Nothing
    81. End Sub
    82.  
    83. 'User login
    84. Public Function DoLogin(ByVal strName As String, ByVal strPwd As String) As Boolean
    85.     Dim rs As Recordset, rows As Integer
    86.     gUserId = vbNullString 'login is not success
    87.     gLogined = False
    88.     Set rs = QuerySql("select [Id], [UserName], [Pwd] from [Users] where [LoginName] like '" & strName & "'")
    89.     If Not rs Is Nothing Then
    90.         If rs.State = adStateOpen Then
    91.             While Not rs.EOF
    92.                 rows = 1
    93.                 If strPwd = rs("Pwd") Then
    94.                     gLoginName = strName 'login name
    95.                     gUserId = rs("Id") 'login user idV
    96.                     gUsreName = IIf(IsNull(rs("UserName")), "", rs("UserName")) 'user name
    97.                     gLogined = True
    98.                     DoLogin = True 'login is success
    99.                 End If
    100.                 rs.MoveNext
    101.             Wend
    102.             rs.Close
    103.         End If
    104.         If Not DoLogin Then gErrDescription = IIf(rows = 0, "User doesn't Exist£¡", "Invalid Password£¡")
    105.     End If
    106.     Set rs = Nothing
    107. End Function
    108.  
    109. 'check the authorize access
    110. Public Function CheckRight(ByVal strModuleName As String) As Boolean
    111.     Dim rs As New Recordset, vflag As Boolean
    112.     Set rs = QuerySql("select [Availability] from vUserAllRight where [LoginName] like '" & gLoginName & _
    113.             "' and [ModuleName] like '" & strModuleName & "'")
    114.     If Not rs Is Nothing Then
    115.         If rs.State = adStateOpen Then
    116.             While Not rs.EOF
    117.                 vflag = vflag Or rs("Availability")
    118.                 rs.MoveNext
    119.             Wend
    120.             rs.Close
    121.         End If
    122.         CheckRight = vflag
    123.     End If
    124.     Set rs = Nothing
    125. End Function
    126.  
    127. 'check the Value is exists at table
    128. Public Function CheckValueIsExists(ByVal TableName As String, _
    129.         ByVal FieldName As String, ByVal strValue As String, _
    130.         Optional ByVal strEliminate As String = vbNullString) As Boolean
    131.     Dim rs As New Recordset, strsql As String
    132.     strsql = "select count(*) as [RowCount] from [" & TableName & _
    133.         "] where [" & FieldName & "] = '" & Replace(strValue, "'", "''") & "'"
    134.     'at modify state, eliminate self
    135.     If Len(strEliminate) > 0 Then strsql = strsql & " and [Id] <> " & strEliminate
    136.     Set rs = QuerySql(strsql)
    137.     If Not rs Is Nothing Then
    138.         If rs.State = adStateOpen Then
    139.             CheckValueIsExists = (rs("RowCount") > 0)
    140.             rs.Close
    141.         End If
    142.     End If
    143. End Function
    Thanks!
    Last edited by si_the_geek; Jan 12th, 2007 at 10:26 AM. Reason: corrected a VBcode tag

  18. #18
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: records retreive extremely slow

    You have 2 functions both named OpenRecordset?
    Also, unless I missed it, where do you set rs to anything?
    Tengo mas preguntas que contestas

  19. #19
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: records retreive extremely slow

    I think they both OpenRecordset's are the same one, just posted twice.

    The setting of rs is done, but it is very dubious - it is done by "Dim As New"
    Instead it should be done with a Set, and you should clear it when possible (to avoid memory issues etc), eg:
    VB Code:
    1. ..
    2.     [U]Dim rs As Recordset  
    3.     Set rs = New Recordset[/U]
    4.     If OpenConn Then 'aviod time ping out
    5.         On Error GoTo TrackErr
    6.         rs.Open strsql, conn, CursorType, LockType
    7.     End If
    8.     Set OpenRecordset = rs
    9.     [U]Set rs = Nothing[/U]
    10. ..

    In Sub Main you have a very bad piece of code - a single word that should always be avoided, which is End. In this case you should replace it with Exit Sub (as the program ends safely when there is no more code to run, and no forms open), eg:
    VB Code:
    1. If Not gLogined Then Exit Sub

    I assume frmLogin basically (after user input) just calls DoLogin, correct?

    In several of your SQL statements you have used "like" instead of "=", is there a reason for that?

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    si_the_geek:
    i has been try the method you mention above,but the problem still remain the same,records retreive extremely slow until computer hang need to reboot . ya, frmlogin is affert user input click Ok to login will calls Dologin and SQL statements used "like" instead of "=",am i used the wrong method?

    below is frmlogin code:
    VB Code:
    1. Private Sub cmdOK_Click()
    2.     'check corerct password to login
    3.     If Not DoLogin(txtUserName.Text, txtPassword.Text) Then
    4.         MsgBox "Please Enter Correct Password£¡" & gErrDescription, vbCritical, "Warning"
    5.         Exit Sub
    6.     End If
    7.     Unload Me
    8. End Sub

    Thanks!
    Last edited by gracehskuo; Jan 12th, 2007 at 07:41 PM.

  21. #21
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: records retreive extremely slow

    Try putting breakpoints in your code at the start of each module. See which ones you hit quickly. Then, when you don't hit the next one, you'll know the previous one is where your problem is.
    Then step through the code in that module to see which line causes the delay.
    This is kind of a brute force method to find the problem, but should work to identify it.
    Tengo mas preguntas que contestas

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    salvelinus:
    i try your method to putting breakpoints at the start of each module.i found the speed run very slow at this module location.

    VB Code:
    1. Public Function OpenRecordset(ByVal strsql As String, _
    2.         Optional ByVal CursorType As CursorTypeEnum = CursorTypeEnum.adOpenForwardOnly, _
    3.         Optional ByVal LockType As LockTypeEnum = LockTypeEnum.adLockReadOnly) As Recordset
    4.     Dim rs As New Recordset
    5.     Set rs = New Recordset
    6.     If OpenConn Then 'aviod time ping out
    7.         On Error GoTo TrackErr
    8.         rs.Open strsql, conn, CursorType, LockType
    9.     End If
    10.     Set OpenRecordset = rs
    11.     Set rs = Nothing
    12.     Exit Function
    13. TrackErr:
    14.     gErrDescription = Err.Description
    15.     Err.clear
    16. End Function

    Thanks!
    Last edited by gracehskuo; Jan 12th, 2007 at 08:47 PM.

  23. #23
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: records retreive extremely slow

    Ok, then when you get to that module, step through that code to see which line causes the problem. You can do that when you hit the breakpoint in that module by using the debug menu, or, I think, hitting F8. That will walk you through the code line by line.
    The problem could be in OpenConn, since you call that. Stepping through will help with that.
    Per Si above, also change the way you declare rs.
    Tengo mas preguntas que contestas

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    salvelinus:
    i have try the F8 method go through the code line by line.i can't found any problem at this moment.now is run the first and second time retreive record will get faster,but third time login to retreive record it will back very slow.
    help please!

    Thanks!
    Last edited by gracehskuo; Jan 13th, 2007 at 01:29 AM.

  25. #25
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: records retreive extremely slow

    Well, I'm going on vacation to Barbados, so probably can't work through this with you. But if it works ok first time, slows down later, you might want to look at memory resources.
    First, obviously, is do you have enough memory on your machine for what you want to do? This isn't as big a problem as it used to be, but I still see machines with 32 mb memory trying to run more modern apps.
    Second, do you close objects and Set them to Nothing - rs, etc - when you're done with them? If performance gets worse with each run, this would be a good place to look.
    If it's not too large, and you're allowed to do it, you might want to zip up your db and post it here, so people can check it out.
    Tengo mas preguntas que contestas

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    salvelinus:
    Gratitude your suggestion.my laptop memory is 1gb,so i think may not a problem to run the project.i will check agian the close object and Set them to Nothing.
    by the way how to post the zip file here?

    Thanks!

  27. #27
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: records retreive extremely slow

    Yes, 1 gb of memory should work
    To post an attachment, first zip your file using Winzip or whatever program you may have to zip files. Then when you click "Reply", towards the bottom of the screen (scroll if necessary) you'll see a section to "Attach Files" with a button "Manage Attachments"
    Tengo mas preguntas que contestas

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    this is my zip file.
    Attached Files Attached Files

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    re-upload database file.if the previous post database can't open,please refer to this database file.

    username & password is same:
    1)qc
    2)production
    3)autolathe

    Thanks!
    Attached Files Attached Files

  30. #30
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: records retreive extremely slow

    Okay so I've tried your project and see a lot of problems.

    Memory Issues ( took more than 1G of memory )
    You have to fix your code and be sure to Set your objects or recordset to Nothing. Binding a database is not of my choice.

    VB Code:
    1. Set m_rs = OpenRecordset("select * from [Inventory]" & vbCrLf & _
    2.                             "where ([Location] in (" & vbCrLf & _
    3.                             "  select [DepartmentName] from [Department]" & vbCrLf & _
    4.                             "  where [Id] in (" & vbCrLf & _
    5.                             "    select [DepartmentID] from [UserDepartment]" & vbCrLf & _
    6.                             "    where [UserId] = '" & gUserId & "'" & vbCrLf & _
    7.                             "  )" & vbCrLf & _
    8.                             ") or exists(SELECT * FROM UserRoles WHERE [UserId] = " & gUserId & _
    9.                             " and [RoleId] in (select [Id] from [Roles] where [RoleName] = 'admin')))" & _
    10.                             " and Deletedate is null", adOpenStatic, adLockOptimistic)
    11.     Set DataGrid1.DataSource = m_rs

    You got to fix your query.

    You also overlook some null values. you can add "" and .Value.

    VB Code:
    1. While Not rs.EOF
    2.         total = total + rs("Price")[B].Value[/B] [B]& ""[/B]
    3.         DataReport1.Sections("Section2").Controls.Item("Label9").Caption = rs("Location") '"Department:" & rs("Location")
    4.         rs.MoveNext
    5.     Wend

    That's all I can help for now. I having difficulty debbuging it because it hangs after compiling. Maybe you got to consider memory issues.

  31. #31
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: records retreive extremely slow

    Why do you need all those vbcrlf's in a SQL statement? It makes no sense to me.

    Do you have any indexes set on your database?

    VB Code:
    1. Set m_rs = OpenRecordset("select * from [Inventory]" & vbCrLf & _
    2.                             "where ([Location] in (" & vbCrLf & _
    3.                             "  select [DepartmentName] from [Department]" & vbCrLf & _
    4.                             "  where [Id] in (" & vbCrLf & _
    5.                             "    select [DepartmentID] from [UserDepartment]" & vbCrLf & _
    6.                             "    where [UserId] = '" & gUserId & "'" & vbCrLf & _
    7.                             "  )" & vbCrLf & _
    8.                             ") or exists(SELECT * FROM UserRoles WHERE [UserId] = " & gUserId & _
    9.                             " and [RoleId] in (select [Id] from [Roles] where [RoleName] = 'admin')))" & _
    10.                             " and Deletedate is null", adOpenStatic, adLockOptimistic)

  32. #32
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: records retreive extremely slow

    randem is correct. Use the _ line break in your code for readability, but you don't actually have to line break your code.
    Tengo mas preguntas que contestas

  33. #33

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    randem,salvelinus:
    you mean the code need to change to this way without the vbcrLf?from the database didn't set any indexes.

    VB Code:
    1. Set m_rs = OpenRecordset("select * from [Inventory]" & _
    2.                             "where ([Location] in (" & _
    3.                             "  select [DepartmentName] from [Department]" & _
    4.                             "  where [Id] in (" & _
    5.                             "    select [DepartmentID] from [UserDepartment]" & _
    6.                             "    where [UserId] = '" & gUserId & "'" & _
    7.                             "  )" & _
    8.                             ") or exists(SELECT * FROM UserRoles WHERE [UserId] = " & gUserId & _
    9.                             " and [RoleId] in (select [Id] from [Roles] where [RoleName] = 'admin')))" & _
    10.                             " and Deletedate is null", adOpenStatic, adLockOptimistic)

    Thanks!

  34. #34
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: records retreive extremely slow

    If you don't have indexes your retrieval will be slow. This is also greatly affected by the type of data types that are indexed.

  35. #35

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    please help i has change the query code to this way,but the query statement ll contain some error....please help to correct the error.
    VB Code:
    1. Set m_rs = OpenRecordset(select * from Inventory
    2.                             where Location=(select (DepartmentName)
    3.                             from (Department)
    4.                             where (Id) =(select (DepartmentID) from (UserDepartment)
    5.                             where [UserId] = '" & gUserId & "'"& _" ))
    6.                     or exists(SELECT * FROM UserRoles WHERE [UserId] = " & gUserId & _
    7.                             and [RoleId] in (select [Id] from [Roles] where [RoleName] = 'admin')))" & _
    8.                             and Deletedate is null", adOpenStatic, adLockOptimistic)
    9.  
    10. code

    Thanks!

  36. #36
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: records retreive extremely slow

    Some Errors????? You could help a lo by telling us what exactly the errors are...
    Try doing this and your errors will be clear
    VB Code:
    1. SQL = "select * from Inventory
    2.                             where Location=(select (DepartmentName)
    3.                             from (Department)
    4.                             where (Id) =(select (DepartmentID) from (UserDepartment)
    5.                             where [UserId] = '" & gUserId & "'"))
    6.                     or exists(SELECT * FROM UserRoles WHERE [UserId] = " & gUserId & _
    7.                             and [RoleId] in (select [Id] from [Roles] where [RoleName] = 'admin')))" & _
    8.                             and Deletedate is null")
    9.  
    10. Debug.Print SQL

  37. #37
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: records retreive extremely slow

    I can't even log onto your system without system errors (Selected collating sequence not supported by the operating system).

    BTW: Your database is designed all wrong. You use text fields for everything except date/time fields. Why do you use text fields for numbers? Indexing and searching will be horribly slow.
    Last edited by randem; Jan 15th, 2007 at 01:56 AM.

  38. #38
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: records retreive extremely slow

    It will help if the items you use to select from are indexed and numeric fields. Lookup tables are ideal for this.

  39. #39

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    584

    Re: records retreive extremely slow

    randem:
    can't logon to the system?mean you can't even open the project file?
    you mean using text fields for numbers will cause the system run very slow?so that the system keep hang? i has change the number to number field,but it seem not much improve.

    Thanks!
    Last edited by gracehskuo; Jan 15th, 2007 at 03:13 AM.

  40. #40
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: records retreive extremely slow

    Of course I can open the project file. You have a logon screen that fails when executing the statement to get the user information to check it.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width