G
Guest
When I set the Timeout property of a command I am executing it does not end
when it reaches the timeout value specified. Here is the code I am using. My
sample query is simply returning all rows from a table with approximately
170,000 rows. The dataadapter.Fill takes between 8 and 10 seconds.
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim datStartTime As DateTime
Dim datEndTime As DateTime
Try
cnn = New SqlConnection
cmd = New SqlCommand
da = New SqlDataAdapter
ds = New DataSet
cnn.ConnectionString = " - Removed for security reasons - "
cnn.Open()
cmd.Connection = cnn
cmd.CommandTimeout = 2
cmd.CommandText = " - Removed for security reasons - "
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
datStartTime = Now
da.Fill(ds)
datEndTime = Now
Me.txtDuration.Text =
datEndTime.Subtract(datStartTime).TotalSeconds.ToString & " seconds"
Me.DataGrid1.DataSource() = ds.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
If Not cmd Is Nothing Then
cmd.Dispose()
End If
If Not cnn Is Nothing Then
cnn.Dispose()
End If
End Try
when it reaches the timeout value specified. Here is the code I am using. My
sample query is simply returning all rows from a table with approximately
170,000 rows. The dataadapter.Fill takes between 8 and 10 seconds.
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim datStartTime As DateTime
Dim datEndTime As DateTime
Try
cnn = New SqlConnection
cmd = New SqlCommand
da = New SqlDataAdapter
ds = New DataSet
cnn.ConnectionString = " - Removed for security reasons - "
cnn.Open()
cmd.Connection = cnn
cmd.CommandTimeout = 2
cmd.CommandText = " - Removed for security reasons - "
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
datStartTime = Now
da.Fill(ds)
datEndTime = Now
Me.txtDuration.Text =
datEndTime.Subtract(datStartTime).TotalSeconds.ToString & " seconds"
Me.DataGrid1.DataSource() = ds.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
If Not cmd Is Nothing Then
cmd.Dispose()
End If
If Not cnn Is Nothing Then
cnn.Dispose()
End If
End Try