Solved

Adding a TimeOut parameter to a <asp:SQLDataSource

Posted on 2008-10-24
3
1,142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

718 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