PC Review


Reply
Thread Tools Rate Thread

Command.Timeout Property Not Working

 
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      24th Feb 2005
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


 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      24th Feb 2005
CommandTimeout doesn't apply to fetching data - is affects just command
execution.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Brad" <(E-Mail Removed)> wrote in message
news:FA7CD885-B05B-45E7-9B6D-(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      28th Feb 2005
Miha,

Can you explain your answer in more detail? I thought part of completing
the command was fetching the data.

- Brad

"Miha Markic [MVP C#]" wrote:

> CommandTimeout doesn't apply to fetching data - is affects just command
> execution.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "Brad" <(E-Mail Removed)> wrote in message
> news:FA7CD885-B05B-45E7-9B6D-(E-Mail Removed)...
> > 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
> >
> >

>
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      1st Mar 2005
Hi Brad,

When you're trying to execute a SELECT command and fill data to a DataSet,
the process is actually divided into 2 parts.

1. A cursor is opened on server. A DataReader object is opened.
2. Fill is going though every row in the rowset and fetching data to the
DataSet.

The Timeout property only applies to the opening of a DataReader. The
latter part is a big deal but not controlled by SqlCommand.Timeout property.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      4th Mar 2005
Kevin,

Is it possible to use a Try...Catch block to capture the exception thrown
when a timeout occurs? Also when a timeout occurs are changes automatically
rolled back or would I need to handle the rollback in the application code?

- Brad

"Kevin Yu [MSFT]" wrote:

> Hi Brad,
>
> When you're trying to execute a SELECT command and fill data to a DataSet,
> the process is actually divided into 2 parts.
>
> 1. A cursor is opened on server. A DataReader object is opened.
> 2. Fill is going though every row in the rowset and fetching data to the
> DataSet.
>
> The Timeout property only applies to the opening of a DataReader. The
> latter part is a big deal but not controlled by SqlCommand.Timeout property.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      5th Mar 2005
Hi Brad,

We cannot use a Try...Catch block to catch the timeout exception, since in
this senario, there is no exception thrown. The transaction will not be
rollbacked. If there is exception throw when opening a DataReader, it can
be caught. And the transaction is rollbacked. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing timeout property of formsauthentication Eric Microsoft Dot NET Framework 0 10th Aug 2006 04:40 PM
ado command timeout property Loane Sharp Microsoft Excel Programming 0 16th Oct 2005 10:23 AM
SoapHttpClientProtocol and the TimeOut property Kim Microsoft C# .NET 0 15th Aug 2005 12:12 PM
Re: timeout property not working Marina Microsoft Dot NET 2 7th Sep 2004 06:01 PM
Timeout property =?Utf-8?B?TWFyY28=?= Microsoft C# .NET 1 20th Apr 2004 03:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:01 PM.