![]() |
|
|
|||||||
![]() |
ASP Net - How to set commandTimeout for ObjectDataSource (ASP.NET 2.0)? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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. Piotrek |
|
|
|
|
#2 |
|
Posts: n/a
|
Anybody?
|
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
Thanks jd.
However, I don't want to set Connection timeout but Command timeout. In connection string only Connection timeout can be set. Piotrek |
|
|
|
#5 |
|
Posts: n/a
|
How about setting the CommandTimeout property?
-- jeff |
|
|
|
#6 |
|
Posts: n/a
|
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 |
|
|
|
#7 |
|
Posts: n/a
|
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. "Piotrek" <> wrote in message news: oups.com... > 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 > |
|
|
|
#8 |
|
Posts: n/a
|
You can't set it globally, so you must set it for each Command object.
The Command object has a CommandTimeout property you can set. See examples at : http://msdn.microsoft.com/library/de... outtopic.asp 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" <> wrote in message news: oups.com... > 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 > |
|
|
|
#9 |
|
Posts: n/a
|
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[i] != null)) { ((System.Data.SqlClient.SqlCommand)(this._commandC ollection[i])).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.SelectCommandTim eout = 180 but this TableAdapter is not seen in IntelliSense. Piotrek |
|
|
|
#10 |
|
Posts: n/a
|
re:
> I would like to do sth like that (e.g. in the Page_Load event): > P_RWI_PAYMENTS_SEARCHTableAdapter.SelectCommandTim eout = 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" <> wrote in message news: oups.com... > 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[i] != null)) > { > > ((System.Data.SqlClient.SqlCommand)(this._commandC ollection[i])).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.SelectCommandTim eout = 180 > but this TableAdapter is not seen in IntelliSense. > > Piotrek > |
|