How to set commandTimeout for ObjectDataSource (ASP.NET 2.0)?

P

Piotrek

HI all.

In my web site I have some ObjetDataSource. Its business object
property is set to my dataset I created in dataset designer (this
dataset has table adapter).

My question is: how can I set command timeout property for fill method
from this table adapter?

Thanks in advance,
Piotrek.
 
J

jd

The timeout is normally set in the connection string. I don't know if
there's another place to specify it. If you want to use the same
timeout everywhere in your program, then just set the timeout value
globally. If you want to use different timeouts in different places,
you can dynamically build the connection string (note, however, that
this may reduce the effectiveness of connection pooling).

Hope this helps...

-- jeff
 
P

Piotrek

Thanks jd.

However, I don't want to set Connection timeout but Command timeout. In
connection string only Connection timeout can be set.

Piotrek
 
P

Piotrek

Jd, that's exaclty what I want to do.

Just tell me, where I can find this CommandTimeout property (remember,
that I use auto generated table adapters).

Piotrek
 
K

Kevin Spencer

It's fine to use autogenerated code, but at some point you need to tweak it.
In this case, you have code that creates a TableAdapter. A TableAdapter is a
wrapper for a DataAdapter. The DataAdapter in the Table Adapter has 4
different Command objects associated with it, one each for inserting,
selecting, updating, and deleting. The Command object has the CommandTimeout
property which can be used to adjust this.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
P

Piotrek

Thanks for all answers.

I created a partial class, in which there is a SelectCommandTimeout
property:
namespace DataSetPaymentsTableAdapters
{
public partial class P_RWI_PAYMENTS_SEARCHTableAdapter
{
public int SelectCommandTimeout
{
get
{
return (this._commandCollection[0].CommandTimeout);
}


set
{
for (int i = 0; i < this._commandCollection.Length;
i++)
{
if ((this._commandCollection != null))
{

((System.Data.SqlClient.SqlCommand)(this._commandCollection)).CommandTimeout
= value;
}
}
}
}


}
}

My solution compiles without errors, but I do not how to call this
newly created property from the page, on which I have my
ObjectDataSource.

I would like to do sth like that (e.g. in the Page_Load event):
P_RWI_PAYMENTS_SEARCHTableAdapter.SelectCommandTimeout = 180
but this TableAdapter is not seen in IntelliSense.

Piotrek
 
J

Juan T. Llibre

re:
I would like to do sth like that (e.g. in the Page_Load event):
P_RWI_PAYMENTS_SEARCHTableAdapter.SelectCommandTimeout = 180
but this TableAdapter is not seen in IntelliSense.

It's simpler to set the Timeout in code :

<DataObjectMethod(DataObjectMethodType.Delete)> _
Public Shared Function DeleteEmployee(EID As Integer) As Boolean

If Not _initialized Then Initialize()

Dim conn As SqlConnection = New SqlConnection(_connectionString)
Dim cmd As SqlCommand = New SqlCommand("DELETE FROM E WHERE EID = @EmployeeID", conn)
cmd.CommandTimeout = 20
cmd.Parameters.Add("@EmployeeID", SqlDbType.Int).Value = EID

Try
conn.Open()

If cmd.ExecuteNonQuery() <> 0 Then _
Return False
Catch e As SqlException
' Handle exception.
Finally
conn.Close()
End Try

Return True
End Function



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Piotrek said:
Thanks for all answers.

I created a partial class, in which there is a SelectCommandTimeout
property:
namespace DataSetPaymentsTableAdapters
{
public partial class P_RWI_PAYMENTS_SEARCHTableAdapter
{
public int SelectCommandTimeout
{
get
{
return (this._commandCollection[0].CommandTimeout);
}


set
{
for (int i = 0; i < this._commandCollection.Length;
i++)
{
if ((this._commandCollection != null))
{

((System.Data.SqlClient.SqlCommand)(this._commandCollection)).CommandTimeout
= value;
}
}
}
}


}
}

My solution compiles without errors, but I do not how to call this
newly created property from the page, on which I have my
ObjectDataSource.

I would like to do sth like that (e.g. in the Page_Load event):
P_RWI_PAYMENTS_SEARCHTableAdapter.SelectCommandTimeout = 180
but this TableAdapter is not seen in IntelliSense.

Piotrek
 
P

Piotrek

Hi Juan.
It's simpler to set the Timeout in code :
I know that, however as I said I did not write any line of code -
everything was autogenerated by DataSet Designer. It would be great if
I could change this generated code by setting there timeout.
Unfortunately I cannot find this code. Morover I think that every time
I change something in my dataset then this code would be generated one
more time and my changes would be overridden.

Piotrek
 
U

usenetlex

Hey, did you ever figure this out?
I am having the same problem - in the DataSet desginer, I do not see a
way to set the CommandTimeout (just the CommandText, CommandType,
etc.).
Changing the code... well I would lose it on the next auto-generate.
And the command variables are private.
ARGH.
 
P

Piotrek

No I didn't. I just wrote my own DAL class instead of that one, which
was generated by DataSet Designer.

Piotrek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top