Solved

Adding a TimeOut parameter to a <asp:SQLDataSource

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

947 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

18 Experts available now in Live!

Get 1:1 Help Now