1

I have a XSD file that I use to connect my application. I have my table adapter and methods to access my queries in a separate cs file. I want to increase my time out limit. I have seen other solution that kind of point this:

    [System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
    public Scout.ScoutDataTable GetItems(string node, int rank1, int rank2)
    {
        ScoutTableAdapter Adapter = new ScoutTableAdapter();
        Adapter.Adapter.SelectCommand.CommandTimeout = 60;
        return Adapter.GetDataBy(node, rank1, rank2);
    }

However I get null reference on the line set the timeout = 60. I have looked at the error and I am confused on what is causing me the problem.

5
  • Is the SelectCommand property null? Commented Jan 5, 2012 at 21:36
  • @KevRitchie I think that maybe my problem. Commented Jan 6, 2012 at 14:24
  • Hi @Joe, did you manage to get this fixed? Commented Jan 9, 2012 at 9:39
  • @KevRitchie I haven't figured how to fill the SelectCommand but at least I have identified the problem. Commented Jan 9, 2012 at 15:35
  • What code do you have in your GetDataBy method? Could you set the CommandTimeout in there? Commented Jan 9, 2012 at 16:01

1 Answer 1

2

This might be a bit of a late answer but might help someone with the same problem so ...

The idea is to create a base class for the table adapter too inherit which increases the timeout for all commands in the table adapter. It has to use reflection since the generated table adapters don't inherit anything useful. It exposes a public function to alter the timeout.

using System;
using System.Data.SqlClient;
using System.Reflection;

namespace CSP
{
    public class TableAdapterBase : System.ComponentModel.Component
    {
        public TableAdapterBase()
        {
        }

        public void SetCommandTimeout(int Timeout)
        {
            foreach (var c in SelectCommand())
                c.CommandTimeout = Timeout;
        }

        private System.Data.SqlClient.SqlConnection GetConnection()
        {
            return GetProperty("Connection") as System.Data.SqlClient.SqlConnection;
        }

        private SqlCommand[] SelectCommand()
        {
            return GetProperty("CommandCollection") as SqlCommand[];
        }

        private Object GetProperty(String s)
        {
            return this.GetType().GetProperty(s, BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance).GetValue(this, null);
        }
    }
}

So your example would become:

[System.ComponentModel.DataObjectMethodAttribute
    (System.ComponentModel.DataObjectMethodType.Select, false)]
public Scout.ScoutDataTable GetItems(string node, int rank1, int rank2)
{
    ScoutTableAdapter Adapter = new ScoutTableAdapter();
    Adapter.SetCommandTimeout(60);
    return Adapter.GetDataBy(node, rank1, rank2);
}

in the dataset designer the default base class is System.ComponentModel.Component just set it to the above class TableAdapterBase

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.