March 8, 2007 at 11:39 am
Can someone PLEASE help me with a quick fix? The function below is timing out. I was told that I needed to 'Solved it by setting the timeout property to command object' but I do not know how to do this. Please Help!!!
Thank you.....
Private
Function Data2Array() As Array
Try
If (dbConnection.State = ConnectionState.Closed) Then dbConnection.Open()
'select count(*) from TimesheetStudentActions where stuAction='feedback'
Dim dTable As New DataTable("temp")
Dim dtAdapter As New SqlDataAdapter("SELECT SECTIONID,SCHLSTUID,convert(varchar(10),cast(DAYACCESSED as dateTime),101), " & _
" ACTIONID, DATEPART(ww,convert(varchar(10),cast(DAYACCESSED as dateTime),101)) WeekOfYear, " & _
" DATEPART(dw,convert(varchar(10),cast(DAYACCESSED as dateTime),101)) DayOfWeek FROM " & _
" TimesheetStudentActions WHERE stuAction <> 'feedback' AND IsNull(ynPROCESSED,0) = 0 AND SCHLSTUID IN (SELECT SCHLSTUID From TimesheetStudent)", dbConnection)
dtAdapter.Fill(dTable)
Dim intArraycounterMax As Integer = dTable.Rows.Count - 1
Dim intFieldcounterMax As Integer = dTable.Columns.Count - 1
Dim intFieldcounter As Integer
Dim MyArray(intArraycounterMax, intFieldcounterMax) As String
Dim intarraycounter As Integer = 0
Dim dRow As DataRow
For Each dRow In dTable.Rows
For intFieldcounter = 0 To intFieldcounterMax
Try
MyArray(intarraycounter, intFieldcounter) = dRow(intFieldcounter)
Catch ex1 As InvalidCastException
' Nothing to do Nulls are ok
Finally
End Try
Next
intarraycounter += 1
Next
Return (MyArray)
Catch ex As Exception
WriteToLogFile("Exception: " + ex.Message + ex.StackTrace, sImportErrorFile)
Finally
If Not (dbConnection Is Nothing) Then
If (dbConnection.State = ConnectionState.Open) Then
dbConnection.Close()
End If
End If
End Try
End Function
March 8, 2007 at 12:12 pm
The Timeout property is on a SqlCommand object.
You are constructing a SqlDataAdapter with a hard-coded SQL string, which (I think) will result in the SqlDataAdapter's SelectCommand property being set.
Therefore, to set the timeout property, you'd do something like this:
dtAdapter.SelectCommand.CommandTimeout = {whatever timeout you want}
If that does not work, then you need to look at constructing your SqlDataApter using a different constructor, that takes a SqlCommand object instead of a string. In that case, you construct a SqlCommand, set its SQL statement and CommandTimeout properties, then construct a SqlDataAdapter with it.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply