Tuesday, January 16, 2007

TimeOut Expired in ado.net and sql server

Some times we feel if we can speed up the sqlserver , or database, and get rid of the a specific problem named "timeout expired"





here`s a link for the same , and now onwards u will not pray to god, we have solution at ur hand

let`s go

thanks
Pradeep Tiwari

Monday, January 15, 2007

timeout expired - ado.net

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Help for ADO.net objects

Some times we get “timeout expired” error.
It may be because of actually time allocated to a particular operation is getting timeout so start debugging.

1st thing to keep in mind is there is two types of time out
1. Connection time out (which is property (read only) of connection object) default (15 sec)
2. Command time out (which is property (read , write) of command object) default (30 sec)

To start with 1st one means Connection Time out : solution is to increase the value say 60 seconds
And for this you will rush to your connection object and as u got a property named ConnectionTimeout and u wil put the code
conn.ConnectionTimeout = 60; (60 seconds)

and according to you every thing is okey, BUT NOT ACCORDING TO ADO.NET
this is read only property.
Work around is to chage your connection string (usually we have this in our web.config or app.config) by putting “connection timeout = 60” or “connect timeout = 60”



Now is you check your connection string, it will use 60 seconds value.

This solution may or may not resolve the problem as there is an another operation connection to this “command” and command it self call time out.

This is 2nd case

To start with Command Time out : solution is increase the value say 60 seconds
And again for this you will rush to ur web.config or app.config and try to accommodate “command timeout = 60” but this will not work for your kind information, information placed at this place is used by connection not by command object.
The work around is, command.commandTimeout is a read and write property means you can set the value directly in code.
Like “Command.CommandTimeout = 900”, if u r using DataAdopter, not a issue just use its proper command type (select, update , delete).
And set this property to a numeric value.

(best example of lateral thinking)

or you can access the same at
timeout Expired