I am creating a DS on the fly when a GV is rendered, and I am trying to figure out how to set the selecting's CommandTimeout property to see if I can extend it enough to give the underlying query time to complete. Below is the code that I am using to create
the DS but not sure how to access the CommandTimeout property without creating a Selecting event for the datasource, but since it is not actually available till page load the event errors out.
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim gv As GridView = e.Row.FindControl("GridView2")
Dim dbSrc As New SqlDataSource
dbSrc.ConnectionString = ConfigurationManager.ConnectionStrings("EWareCallsConnectionString").ConnectionString
dbSrc.SelectCommand = "My Select Statement"
dbSrc.SelectParameters.Clear()
dbSrc.SelectParameters.Add("CallMonth", DropDownList1.SelectedValue.ToString)
dbSrc.SelectParameters.Add("CallYear", DropDownList2.SelectedValue.ToString)
gv.DataSource = dbSrc
gv.DataBind()
End If
End Sub
Gatorzlair
Member
117 Points
103 Posts
Programatically setting DataSource Timeout on Selecting
Jul 02, 2012 07:35 PM|LINK
I am creating a DS on the fly when a GV is rendered, and I am trying to figure out how to set the selecting's CommandTimeout property to see if I can extend it enough to give the underlying query time to complete. Below is the code that I am using to create the DS but not sure how to access the CommandTimeout property without creating a Selecting event for the datasource, but since it is not actually available till page load the event errors out.
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then Dim gv As GridView = e.Row.FindControl("GridView2") Dim dbSrc As New SqlDataSource dbSrc.ConnectionString = ConfigurationManager.ConnectionStrings("EWareCallsConnectionString").ConnectionString dbSrc.SelectCommand = "My Select Statement" dbSrc.SelectParameters.Clear() dbSrc.SelectParameters.Add("CallMonth", DropDownList1.SelectedValue.ToString) dbSrc.SelectParameters.Add("CallYear", DropDownList2.SelectedValue.ToString) gv.DataSource = dbSrc gv.DataBind() End If End Subcornball76
Participant
1126 Points
210 Posts
Re: Programatically setting DataSource Timeout on Selecting
Jul 02, 2012 07:57 PM|LINK
I don't think you have any way aruond not using the "selecting" event.
In your example though I don't see why you can't use:
and then create the method mySelecting that sets the timeout:
protected void mySelecting(object sender, SqlDataSourceSelectingEventArgs e) { e.Command.CommandTimeout = 6000; }Gatorzlair
Member
117 Points
103 Posts
Re: Programatically setting DataSource Timeout on Selecting
Jul 02, 2012 08:48 PM|LINK
Got the Method created but the first port is throwing an error which in the auto complete for the command "Selecting" is not a property of dbSrc.
Gatorzlair
Member
117 Points
103 Posts
Re: Programatically setting DataSource Timeout on Selecting
Jul 03, 2012 03:51 AM|LINK
is there a library to import or syntax to get to his property?
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Programatically setting DataSource Timeout on Selecting
Jul 04, 2012 07:57 AM|LINK
Hi,
Here is the article about how to set the CommandTimeout programatically:
http://strivinglife.com/words/post/Programmatic-SQL-command-timeout-using-a-SqlDataSource-C-Sharp.aspx
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
Gatorzlair
Member
117 Points
103 Posts
Re: Programatically setting DataSource Timeout on Selecting
Jul 05, 2012 05:27 PM|LINK
This is pretty much what is described above I have the Event.
Protected Sub mySelecting(sender As Object, e As SqlDataSourceSelectingEventArgs) e.Command.CommandTimeout = 6000 End SubBut when I try to add in the DCScr.Selecting It tells me, "that i must use a RaiseEvent" but not sure of the syntax for doing this.
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Programatically setting DataSource Timeout on Selecting
Jul 06, 2012 05:18 AM|LINK
Hi,
Have you added this code in RowDataBound event of GridView:
AddHandler dbSrc.Selecting, AddressOf dbSrc_Selecting
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
Gatorzlair
Member
117 Points
103 Posts
Re: Programatically setting DataSource Timeout on Selecting
Jul 06, 2012 08:13 PM|LINK
Thats the peice i needed.