Hello,
[quoted text, click to view] > The Connection timeout determines how long the provider waits for a free
> Connection--not how long to wait for a command to execute
That was my understanding as well. Still, it _does_ seem to work.
[quoted text, click to view] > Are you getting Connection timeouts or Command timeouts?
Not sure. The exception is "System.Data.SqlClient.SqlException: Timeout
expired." I presume it is the command timeout, as the query itself
takes a couple of minutes.
Here is my test code:
Dim SqlConnectString As String = _
"Data Source=" & Trim(txtSqlServer.Text) & ";" & _
"Initial Catalog=" & Trim(txtDatabase.Text) & ";" & _
"Integrated Security=SSPI;" & _
"Connection Timeout=1000;"
Dim ta As Date = Now
Dim tb As Date
Dim r As Integer
Dim dt As DataTable
Using cnn As New SqlConnection(SqlConnectString)
'open the connection
cnn.Open()
MsgBox("ConnectionTimeout = " & cnn.ConnectionTimeout)
'define the command
Dim cmd As New SqlCommand
cmd.Connection = cnn
cmd.CommandText = "SELECT Top 1 TimeWritten From
Windows_Event_Log Where KeyComputer=57 And KeyEventLog=1 Order by
TimeWritten Desc "
'define the data adapter
Dim da As New SqlDataAdapter(cmd)
da.SelectCommand.CommandTimeout = cnn.ConnectionTimeout
MsgBox("CommandTimeout = " &
da.SelectCommand.CommandTimeout)
'fill the data table
dt = New DataTable
Try
da.Fill(dt)
r = dt.Rows.Count
Catch ex As Exception
MsgBox(ex.ToString)
r = -1
End Try
End Using
tb = Now
MsgBox( _
ta.TimeOfDay.ToString & vbCrLf & _
tb.TimeOfDay.ToString & vbCrLf & _
DateDiff(DateInterval.Second, ta, tb).ToString & " seconds" & vbCrLf
& _
r.ToString & " rows.")