N
Norm Dotti
I'm missing something. While others on this newsgroup have
had unexplained timout exceptions occurring I can't seem
to get them to occur. Perhaps my understanding of how
they're supposed to work is wrong. I've got the following
code. The command takes roughly 50 seconds to execute in
the database yet I never get a timeout exception even
though I've got Timeout specified in the Connection string
and the CommandTimeout property of the Command object. It
simply runs for the 50 seconds and returns happily as if
everything was ok. I've tried various settings for the
Timeout parameter in the Connection string as well as the
CommandTimeout property of the Command object.
Should I be getting an exception? If so, why aren't I? If
not, how do I determine if the database connection has
timed out?
Dim strConnectionString As String = "yada yada;Connect
Timeout=10"
Dim strSQLStatement As String = "SELECT * FROM TABLE"
Try
Dim con As New SqlClient.SqlConnection
(strConnectionString)
Dim cmd As New SqlClient.SqlCommand(strSQLStatement, con)
cmd.CommandTimeout = 5
SqlClient.SqlCommand(strSQLStatement, con)
Dim dstDataSet As New DataSet()
Dim dadDataAdapter As New SqlClient.SqlDataAdapter(cmd)
dadDataAdapter.Fill(dstDataSet)
Catch excSqlExc As System.Data.SqlClient.SqlException
MessageBox.Show(excSqlExc.ToString)
Catch excGeneric As Exception
MessageBox.Show(excGeneric.ToString)
Finally
'Clean up
End Try
had unexplained timout exceptions occurring I can't seem
to get them to occur. Perhaps my understanding of how
they're supposed to work is wrong. I've got the following
code. The command takes roughly 50 seconds to execute in
the database yet I never get a timeout exception even
though I've got Timeout specified in the Connection string
and the CommandTimeout property of the Command object. It
simply runs for the 50 seconds and returns happily as if
everything was ok. I've tried various settings for the
Timeout parameter in the Connection string as well as the
CommandTimeout property of the Command object.
Should I be getting an exception? If so, why aren't I? If
not, how do I determine if the database connection has
timed out?
Dim strConnectionString As String = "yada yada;Connect
Timeout=10"
Dim strSQLStatement As String = "SELECT * FROM TABLE"
Try
Dim con As New SqlClient.SqlConnection
(strConnectionString)
Dim cmd As New SqlClient.SqlCommand(strSQLStatement, con)
cmd.CommandTimeout = 5
SqlClient.SqlCommand(strSQLStatement, con)
Dim dstDataSet As New DataSet()
Dim dadDataAdapter As New SqlClient.SqlDataAdapter(cmd)
dadDataAdapter.Fill(dstDataSet)
Catch excSqlExc As System.Data.SqlClient.SqlException
MessageBox.Show(excSqlExc.ToString)
Catch excGeneric As Exception
MessageBox.Show(excGeneric.ToString)
Finally
'Clean up
End Try