E
eric.burgin
Under the .NET framework 2.0.50727.42, we are encountering a problem
with timeouts while performing a query using a SQL TableAdapter.
Whatever we set the timeout to gets ignored if we call the Fill method
overload that takes a DataTable (or DataSet) only as a parameter. No
matter what the CommandTimeout is set to, the command will run to
completion and never throw a timeout exception. (Note that, when we
run this query in SQL Server Query Analyzer, it takes far longer to
complete than the CommandTimeout we specified in code). The only way
we can get it to time out is to call the Fill method overload which
takes a DataSet, StartRow, MaxRow, Tablename. This is only true when
MaxRow is set to a relatively low value like 100. We are also seeing
that the specified timeout is honored when we use the ExecuteScalar
method of a SQLCommand object.
We have tried this code against 2 different SQL 2000 servers and one
SQL 7 server
Sample Code:
Dim myconnection As New SqlConnection("Data
Source=myDBServerName;Initial Catalog=DBName;Integrated Security=True")
myconnection.Open()
Dim mydatatable As New DataTable
Dim mydataset As New DataSet
Dim mycommand As New SqlCommand("SELECT * FROM tblSomeTable
WHERE (memo LIKE '%') AND (refcode LIKE '2%') AND (acctnumber LIKE
'%')", myconnection)
mycommand.CommandTimeout = 5
Dim mytableadapter As New SqlDataAdapter(mycommand)
Dim returnRows As Int32
mycommand.ExecuteScalar 'This Line WILL timeout
returnRows = mytableadapter.Fill(mydataset, 0, 100,
tblSomeTable) 'This line WILL timeout
returnRows = mytableadapter.Fill(mydatatable) 'This line will
NOT timeout
with timeouts while performing a query using a SQL TableAdapter.
Whatever we set the timeout to gets ignored if we call the Fill method
overload that takes a DataTable (or DataSet) only as a parameter. No
matter what the CommandTimeout is set to, the command will run to
completion and never throw a timeout exception. (Note that, when we
run this query in SQL Server Query Analyzer, it takes far longer to
complete than the CommandTimeout we specified in code). The only way
we can get it to time out is to call the Fill method overload which
takes a DataSet, StartRow, MaxRow, Tablename. This is only true when
MaxRow is set to a relatively low value like 100. We are also seeing
that the specified timeout is honored when we use the ExecuteScalar
method of a SQLCommand object.
We have tried this code against 2 different SQL 2000 servers and one
SQL 7 server
Sample Code:
Dim myconnection As New SqlConnection("Data
Source=myDBServerName;Initial Catalog=DBName;Integrated Security=True")
myconnection.Open()
Dim mydatatable As New DataTable
Dim mydataset As New DataSet
Dim mycommand As New SqlCommand("SELECT * FROM tblSomeTable
WHERE (memo LIKE '%') AND (refcode LIKE '2%') AND (acctnumber LIKE
'%')", myconnection)
mycommand.CommandTimeout = 5
Dim mytableadapter As New SqlDataAdapter(mycommand)
Dim returnRows As Int32
mycommand.ExecuteScalar 'This Line WILL timeout
returnRows = mytableadapter.Fill(mydataset, 0, 100,
tblSomeTable) 'This line WILL timeout
returnRows = mytableadapter.Fill(mydatatable) 'This line will
NOT timeout