sqlcommand.BeginExecuteReader ignores CommandTimeout

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The following finishes in 1 hour instead of erroring after 1 second as
expected.

Dim cn As New System.Data.SqlClient.SqlConnection
cn.ConnectionString = "Server=(local); Database=master; User ID=sa;
Password=passwd; Asynchronous Processing=true;"
cn.Open()

Dim sqlcommand As New System.Data.SqlClient.SqlCommand
sqlcommand.Connection = cn
sqlcommand.CommandTimeout = 1
sqlcommand.CommandText = "waitfor delay '01:00:00'"
Dim iasyncresult As System.IAsyncResult =
sqlcommand.BeginExecuteReader()
While Not iasyncresult.IsCompleted
System.Threading.Thread.Sleep(1000)
End While

'Note: the following correctly errors after 1 second
'sqlcommand.ExecuteReader()
 
Back
Top