Re: Timeout with Where statement
From: Val Mazur (group51a_at_hotmail.com)
Date: 05/21/04
- Next message: Val Mazur: "Re: Missing ((numeric)) values in recordset causing brain hemorrhaging -- please help!"
- Previous message: --CELKO--: "Re: Newbie question: Fill dataset will ALL tables from database"
- In reply to: Frank Petrucci: "Timeout with Where statement"
- Next in thread: Frank Petrucci: "Re: Timeout with Where statement"
- Reply: Frank Petrucci: "Re: Timeout with Where statement"
- Reply: Frank Petrucci: "Re: Timeout with Where statement"
- Reply: Frank Petrucci: "Re: Timeout with Where statement"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 May 2004 22:47:55 -0400
Hi Frank,
If you have some fields involved into joins or WHERE clause and these fields
are not indexed (you do not have an index for the fields in a database),
then your join could take pretty big amount of time to execute, because
database engine will basically loop through the all records in a table to
make an actual join. Try to work in this area and it should help rather than
increasing timeout time
--
Val Mazur
Microsoft MVP
"Frank Petrucci" <fpetrucci007@yahoo.com> wrote in message
news:AAED88D3-7888-4229-BC40-F266933133F9@microsoft.com...
>I am using MS Access 2000 to access a database on SQL Server 2000 and get a
>time out error running the query below. If I take away the Where statement,
>it works, but when I try to loop for the same date fields, I get errors.
> Thanks,
> Frank
> Option Compare Database
>
> Private Sub Form_Load()
>
>
> ' Initialize variables.
> Dim cn As New ADODB.Connection
> Dim rs As New ADODB.Recordset
> Dim cmd As New ADODB.Command
> Dim sql As String
> Dim fld As ADODB.Field
> Dim ServerName As String
> Dim DatabaseName As String
>
> ' Put text box values into connection variables.
> ServerName = "sec-app-1101"
> DatabaseName = "MS_ROD_TEST"
>
> ' Specify the OLE DB provider.
> cn.Provider = "sqloledb"
>
> ' Set SQLOLEDB connection properties.
> cn.Properties("Data Source").Value = ServerName
> cn.Properties("Initial Catalog").Value = DatabaseName
> 'Stop
> ' Windows NT authentication.
> cn.Properties("Integrated Security").Value = "SSPI"
> 'cn.ConnectionTimeout = 60
> cn.Open
> sql = "Select top 10 * from (GRS.IDX_DOC INNER JOIN GRS.IDX_DOC_PROP ON
> GRS.IDX_DOC.DOC_ID = GRS.IDX_DOC_PROP.DOC_ID) INNER JOIN GRS.IDX_PROP ON
> GRS.IDX_DOC_PROP.PROP_ID = GRS.IDX_PROP.PROP_ID where
> (grs.idx_doc.recorded_date > '1/2/2003') and (grs.idx_doc.recorded_date <
> '1/16/2004')"
> 'Set rs.ActiveConnection = cn
>
> rs.Open sql, cn, adOpenForwardOnly, adLockReadOnly
>
> Set Flds = rs.Fields
> Dim TotalCount As Integer
> TotalCount = Flds.Count
> 'If Flds("DOC_NUM").Value > 732761 Then
> '"1/2/1987" And Flds("GRS.IDX_DOC.RECORDED_DATE").Value < "1/16/1988" Then
> Do While (Not rs.EOF)
> Debug.Print Flds("DOC_NUM").Value
> Debug.Print Flds("RECORDED_DATE").Value
> 'For Each fld In Flds
> ' Debug.Print fld.Value
> Stop
> 'Next
> 'Debug.Print ""
> rs.MoveNext
> Loop
> 'End If
> 'For Each fld In Flds
> ' Debug.Print fld.Name
> ' Stop
> 'Next
> rs.Close
>
> 'MSFlexGrid1.Clear
> ' MSFlexGrid1.AddItem "Product" & Chr(9) & "Value"
> ' Do While (Not rs.EOF)
> ' MSFlexGrid1.AddItem rs.Fields(0).Value & Chr(9) &
> rs.Fields(1).Value
> ' rs.MoveNext
> ' Loop
>
> ' Open the database.
>
>
> cn.Close
>
> End Sub
>
- Next message: Val Mazur: "Re: Missing ((numeric)) values in recordset causing brain hemorrhaging -- please help!"
- Previous message: --CELKO--: "Re: Newbie question: Fill dataset will ALL tables from database"
- In reply to: Frank Petrucci: "Timeout with Where statement"
- Next in thread: Frank Petrucci: "Re: Timeout with Where statement"
- Reply: Frank Petrucci: "Re: Timeout with Where statement"
- Reply: Frank Petrucci: "Re: Timeout with Where statement"
- Reply: Frank Petrucci: "Re: Timeout with Where statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|