Enterprise Data Blocks and command timeout

  • Thread starter Thread starter MarkusJNZ
  • Start date Start date
M

MarkusJNZ

Hi, I am using 2.0 DAB to return a datareader (ASP.NET 2.0)

// Create a database object
Database db =
DatabaseFactory.CreateDatabase("ConnectionString");

I then use the following to return a dataReader

IDataReader _reader = db.ExecuteReader(CommandType.StoredProcedure,
"spStoredProcedureName");

I am experienceing problems where the command times out. How can I set
the command object timeout property when using the above code to
execute a stored procedure against the database??

thanks in advance
Markus
 
Hi,
You should add a <<Timeout>> property in your database connection string
settings .
Yves
 
Hi Markus,

To set the timeout property for the command you have to use an ADO.NET
DbCommand object. Setting the timeout on the connection string will not work
as it is the connection timeout not the command timeout.

For example:

// Create a database object
Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbCommand = db.GetStoredProcCommand("spStoredProcedureName");
dbCommand.CommandTimeout = 600; // Set command timeout to 600 seconds
IDataReader _reader = db.ExecuteReader(dbCommand);

For more info on DbCommand see:
http://msdn2.microsoft.com/en-us/library/system.data.common.dbcommand.commandtimeout.aspx

Regards,

Plamen Ratchev
http://www.SQLStudio.com
 
Thanks everyone for your help
Regards
Markus
Plamen said:
Hi Markus,

To set the timeout property for the command you have to use an ADO.NET
DbCommand object. Setting the timeout on the connection string will not work
as it is the connection timeout not the command timeout.

For example:

// Create a database object
Database db = DatabaseFactory.CreateDatabase("ConnectionString");
DbCommand dbCommand = db.GetStoredProcCommand("spStoredProcedureName");
dbCommand.CommandTimeout = 600; // Set command timeout to 600 seconds
IDataReader _reader = db.ExecuteReader(dbCommand);

For more info on DbCommand see:
http://msdn2.microsoft.com/en-us/library/system.data.common.dbcommand.commandtimeout.aspx

Regards,

Plamen Ratchev
http://www.SQLStudio.com
 
Markus,

You have the following options:

a) determine the default timeout for your connection string
b) create a command, defining the timeout and then using that command to
create the reader

Specifically to b, the code would look like:

Database db = DatabaseFactory.CreateDatabase("teste");

DbCommand cmd = db.GetStoredProcCommand("your stored procedure");

cmd.CommandTimeout = 10000;

IDataReader _reader = cmd.ExecuteReader();

I hope it helps.

Robson,
 
There is a command timeout and a connection timeout.. They are not the same
things.

in the1.1 Ent Lib, I had to code up an overload to specify a larger command
timeout.

I have the 2.0 library (not handy unforunately).....and haven't looked at it
yet, but it is probably the same.
 
Back
Top