Solved

Adding a TimeOut parameter to a <asp:SQLDataSource

Posted on 2008-10-24
3
1,131 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
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…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now