Link to home
Start Free TrialLog in
Avatar of prochko
prochko

asked on

Adding a TimeOut parameter to a <asp:SQLDataSource

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
ASKER CERTIFIED SOLUTION
Avatar of jorge_toriz
jorge_toriz
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prochko
prochko

ASKER

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
Avatar of prochko

ASKER

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