Solved

Adding a TimeOut parameter to a <asp:SQLDataSource

Posted on 2008-10-24
3
1,136 Views
Last Modified: 2012-05-05
Would like to know if there is a way to add a timeout parameter to the <asp:SqlDataSource command.

     <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:MTASP2ConnectionString %>"
            ID="SqlDataViewJobs"
            EnableCaching="true"
            runat="server"
            SelectCommand=""
            DataSourceMode = "DataSet"
            OnSelected="SqlDataViewJobs_Selected">
            <SelectParameters>
            </SelectParameters>
       </asp:SqlDataSource>

I tried an alternative approach (below), but for some reason Sorting and Paging no longer work:

        SqlConnection SqlConn = Data.GetSqlConn();
        SqlConn.Open();
        SqlCommand SqlCmd = new SqlCommand(SQL, SqlConn);
        SqlCmd.CommandTimeout = 120;
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = SqlCmd;
        DataSet myDataSet = new DataSet();
        adapter.Fill(myDataSet);
        GridViewJobs.DataSource = myDataSet.Tables[0];
        GridViewJobs.DataBind();
        SqlConn.Close();
        int count = myDataSet.Tables[0].Rows.Count;

Any advice is appreciated. Thanks
0
Comment
Question by:prochko
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
jorge_toriz earned 250 total points
ID: 22798866
Sorting and Paging do not works because when you sort or change your current page you must Bind your gridView again, is not necessary to do it with you use sqlDataSource
0
 

Author Comment

by:prochko
ID: 22816617
You are correct.  I had to add a bunch of code in order to keep track of the Page Number and Sort Fields (both ASC and DESC).  Here is some of the code:

        if (ViewState["JobsDataSet"] == null)
        {

            SqlConnection SqlConn = Data.GetSqlConn();
            SqlConn.Open();

            SqlCommand SqlCmd = new SqlCommand(SQL, SqlConn);
            SqlCmd.CommandTimeout = 120;
            adapter.SelectCommand = SqlCmd;
            adapter.Fill(myDataSet, "Jobs");
            ViewState["JobsDataSet"] = myDataSet;
            SqlConn.Close();
        }
        else
        {
            myDataSet = (DataSet)ViewState["JobsDataSet"];
        }

        // Prepare the sort expression using the gridSortDirection and gridSortExpression properties
        string sortExpression;
        if (gridSortDirection == SortDirection.Ascending)
            sortExpression = gridSortExpression + " ASC";
        else
            sortExpression = gridSortExpression + " DESC";
        // Sort the data
        myDataSet.Tables["Jobs"].DefaultView.Sort = sortExpression;

        // Bind to the GridView
        GridViewJobs.DataSource = myDataSet.Tables["Jobs"].DefaultView;
        GridViewJobs.DataBind();

It would be a lot, lot easier if there was a way to change the TimeOut parameter on the asp:SqlDataSource control.

Thanks
0
 

Author Closing Comment

by:prochko
ID: 31510520
You are correct.  I had to add a bunch of code in order to keep track of the Page Number and Sort Fields (both ASC and DESC).  Here is some of the code:

        if (ViewState["JobsDataSet"] == null)
        {

            SqlConnection SqlConn = Data.GetSqlConn();
            SqlConn.Open();

            SqlCommand SqlCmd = new SqlCommand(SQL, SqlConn);
            SqlCmd.CommandTimeout = 120;
            adapter.SelectCommand = SqlCmd;
            adapter.Fill(myDataSet, "Jobs");
            ViewState["JobsDataSet"] = myDataSet;
            SqlConn.Close();
        }
        else
        {
            myDataSet = (DataSet)ViewState["JobsDataSet"];
        }

        // Prepare the sort expression using the gridSortDirection and gridSortExpression properties
        string sortExpression;
        if (gridSortDirection == SortDirection.Ascending)
            sortExpression = gridSortExpression + " ASC";
        else
            sortExpression = gridSortExpression + " DESC";
        // Sort the data
        myDataSet.Tables["Jobs"].DefaultView.Sort = sortExpression;

        // Bind to the GridView
        GridViewJobs.DataSource = myDataSet.Tables["Jobs"].DefaultView;
        GridViewJobs.DataBind();

It would be a lot, lot easier if there was a way to change the TimeOut parameter on the asp:SqlDataSource control.

Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question