This is a general scenario we face when we are dealing with data access. In ADO.Net, we access database by creating connections and command objects. If we know that our commands will take long, we increase time out for our commands.
But how should we do that in LINQ to SQL? We don't create any connections are command objects explicitly. Rather we have datacontexts and collections. We generally face timeout issues when we call stored procedures using LINQ To SQL DataContexts. The easiest answer is to change the time out for all data access.
Before presenting the solution let me make this know that LINQ to SQL classes are implemented using Partial classes. You can add definitions to these partial classes in your code. Now, we can define various event handlers in these partial classes other than various other implementation details. One of the event is OnCreated. Here is the solution of this problem by defining OnCreated event handler in partial class of DataContext. The vb.net code is as follows:
Private Sub OnCreated()
Me.CommandTimeout = Integer.MaxValue
End Sub
4 comments:
Thank you for this. It did help me!!!
really nice. your blog is really very nice.thank you for this. it did help me. Please add something extra.
really nice. your blog is really very nice.thank you for this. add more related topic
Really a very nice blog...great work you have done....this is very helpful for us...
Post a Comment