0

In my application written in C# I use OracleDataAdapter.Fill() for fetching data from oracle database. Is there a way to set a timeout for executing this method, because sometimes it is stucked forever?

UPDATE: Instead of "System.Data.OracleClient;" I used "Oracle.DataAccess.Client;" and then code below works good.

using Oracle.DataAcces.Client;
...
OracleDataAdapter yourAdapter = new OracleDataAdapter(strSQLString, connection);
yourAdapter.SelectCommand.CommandTimeout=120;
yourAdapter.fill(yourDataSet);
kjrkvc
  • 115
  • 2
  • 12
  • 1
    I don't think it's a duplicate. This question asks how to set a timeout and the other question asks how to solve a timeout error? – Meta-Knight Aug 20 '15 at 18:47
  • It's not the same question, similar but not the same. The answer on that other question did not help me. – kjrkvc Aug 21 '15 at 06:44

2 Answers2

1

The OracleDataAdapter (as every class derived from the DbDataAdapter base class) has a SelectCommand used to retrieve the data to insert in the target DataSet, this SelectCommand has a property named CommandTimeout that you can set to a time in seconds to raise the Timeout exception

See MSDN DbCommand.CommandTimeout

Steve
  • 213,761
  • 22
  • 232
  • 286
1

try this

    OracleDataAdapter yourAdapter = new OracleDataAdapter(strSQLString, connection);
    yourAdapter.SelectCommand.CommandTimeout=120;
   yourAdapter.fill(yourDataSet);

check the link for knowing more about commandtimeout

shreesha
  • 1,811
  • 2
  • 21
  • 30
  • I cannot asign any number to commandtimeout. even if i do this yourAdapter.SelectCommand.CommandTimeout=120; after this command CommandTimeout is still zero, and that means no time limit – kjrkvc Aug 20 '15 at 11:02
  • what do you mean cannot assign number?are you getting any error? – shreesha Aug 20 '15 at 11:48
  • No, there is no error. It executes without any errors but the value of CommandTimeout is not changed, it is always zero (before and after assignment). – kjrkvc Aug 20 '15 at 12:32
  • check this [link](https://community.oracle.com/message/1025399) to get a complete understanding of commandtimeout. your question helped me to understand a concept.thanks.. – shreesha Aug 20 '15 at 12:55
  • Thank you. This one solved my problem. Instead of "System.Data.OracleClient;" I used "Oracle.DataAccess.Client;" and it works. Thanks. – kjrkvc Aug 21 '15 at 06:41