Linked Questions
24 questions linked to/from When should I dispose of a data context
0 votes
0 answers
83 views
Calling Task.Delay Inside using(dbContext) Block [duplicate]
I found the equivalent of the following in the software I work on: using(var dbContext = Startup.Services.BuildServiceProvider().GetService<ApplicationDbContext>()) { while(true) { ...
15 votes
5 answers
11k views
LinqToSql declare and instantiate DataContext best practice?
What's the best practice in terms of setting up my DataContext for easy access in my extended LinqToSql classes? For example, I have a "User" entity in my dbml and I want to add methods to that ...
8 votes
3 answers
11k views
Do I have to close the SQL Connection manually if I use Linq?
Traditionally, when we use SQL string to done some work, we have to close the sql connection before the page being closed, I was wondering if I use Linq to do the data operations do I still need to ...
5 votes
4 answers
6k views
c#: How to pass linq-objects around
When showing my main window, I make a list of objects from linq-to-sql: using (var context = new Data.TVShowDataContext()) { Shows = new ObservableCollection<Data.Show>(context.Shows); ...
5 votes
4 answers
6k views
Caching Entity Framework DbContexts per request
I have several classes based on System.Entity.Data.DbContext. They get used several times a request in disparate ends of the web application - is it expensive to instantiate them? I was caching a ...
6 votes
3 answers
5k views
Is it possible to gets sql connection leaks using LINQ?
I belived it was not possible to get sql connection leaks when using LINQ, but perfmon tracing of NumberOfReclaimedConnections shows a high number and on high load we sometimes get exceptions like "...
5 votes
3 answers
6k views
Am I using DataContext.Dispose() properly?
I've been getting lots of connection pool timeouts in my ASP.NET MVC project. I've been reading that even though Linq-to-SQL should be disposing for me it doesn't always work and also that not ...
2 votes
3 answers
2k views
Use of the using and DBContext
I am making sure to fully understand this following code: static void Main(string[] args) { var person = new Person {FirstName = "Nadege", LastName = "Deroussen", BirthDate = DateTime.Now}; ...
5 votes
3 answers
2k views
Why are my connections not closed even if I explicitly dispose of the DataContext?
I encapsulate my linq to sql calls in a repository class which is instantiated in the constructor of my overloaded controller. The constructor of my repository class creates the data context so that ...
3 votes
1 answer
4k views
Connection Pool error LINQ to SQL
In Our project I have used LINQ to SQL for every kind of database interaction. Now from what I know , When I create and use DataContext object : it opens the connection , crates a transaction , ...
1 vote
2 answers
2k views
Linq to Sql - DataContext design issues and considerations in ASP.NET MVC application
I am using "Single data context per atomic operation" approach while using Linq to Sql in an ASP.NET MVC application. So far, I have been using a singleton datacontext, which I learnt has many issues,...
3 votes
2 answers
3k views
Is mixing ADO.NET and LINQ-TO-SQL bad? My data layer isn't working
UPDATE As Mathias notes below, this exact problem has been reported and resolved here: ASP.NET-MVC (IIS6) Error on high traffic: Specified cast is not valid ORIGINAL POST This may be too specific a ...
1 vote
3 answers
1k views
How long should I keep my LINQ DataContext around? ASP.Net page
I'm working on a ASP.Net webform app and I am wondering how long I should keep my data context around. Currently I create a context on each page load, and that context is used in every db access for ...
2 votes
2 answers
669 views
DataContext disposed before updating foreign key field
I'm having some problems with DataContexts using linq to sql for an asp.net c# web application. I first had problems with exceptions being thrown as I didn't dispose of the DataContext, same errors as ...
0 votes
2 answers
2k views
Error: ASP.NET: 'DataContext accessed after Dispose.'
There are two tables: Account (id) and BranchId(Id,Name,AccountId) and I have this code in pageload protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { using (...