Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Thanks for your helpful article on:

"Change The Default CommandTimeout of LINQ DataContext

Is there a way to change the SQLClient command timeout in a single global way?

Regards,
Bond Ridhoo.
Posted

Override the OnCreated() method of the DataContext class and use something like the following:

C#
partial void OnCreated()
{
    CommandTimeout = 60; // Use appropriate number.
}
 
Share this answer
 
Comments
BondRidhoo 11-May-10 8:45am    
Thanks for your reply. Which class do I override? The system.data.sqlclient? or the dataset (which I have many in my project) or the table adapter. Sorry I am a bit clueless here.
R. Giskard Reventlov 11-May-10 9:24am    
You're going to override DBDataContext: this is the class that gets created when you select 'Add New Item', 'LINQ to SQL Classes'.

public partial class DBDataContext { ...
Bond

A few things to note here:

1. When you are posting about an article, it's customary to actually post the question against the article. Here, in the quick answers section, it loses context.
2. You should not be thinking about changing the timeout globally as you would be attempting to change the timeout for ALL applications that connect to the database.
3. You can specify the command timeout as part of the connection string. All you need to is add "Connect Timeout"="30" to get a 30 second timeout on the connection for instance.
 
Share this answer
 
Comments
BondRidhoo 11-May-10 8:42am    
Hi. Thanks for the reply. I could not find the 'New Message' in the original post but after submitting the question here, I found that link...Murphy's Law!. Sorry I apologise.
I am referring to Command Timeout and NOT connection Timeout. The connection timeout deals when the app starts up and tries to connect to the db. The command timeout deals with how long to wait for each (maybe long running) query before aborting.
When I mean globally...I mean I have say 10 different datasets, each having many many table adapters. I need to maybe override a class and set the value in a single place instead for each table adapters command object.
Thanks anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900