LinqToSQL and the exception “ ExecuteReader requires an open and available Connection.”

梦想的初衷 提交于 2019-12-24 08:01:26

问题


I have a collection called dbUsers of type IQueryable

These are pulled from a linqtosql database context i.e.

IQueryable<Data.LinqToSQL.User> dbUsers = DBContext.Users

Calling ToList on this object:

IList<Data.LinqToSQL.User> users = dbUsers.ToList();

Results in an exception:

ExecuteReader requires an open and available Connection. The connection's current state is connecting.

What am I doing wrong here?

Cheers


回答1:


see if this works for you:

IList<Data.LinqToSQL.User> users = (from u in DBContext.Users select u).ToList();

if not you might need to do something like:

DBContext context = new DBContext();
IList<Data.LinqToSQL.User> users = (from u in context.Users select u).ToList();



回答2:


I think this is a threading problem with the DataContext. I am getting similar problems. Check this question for more details.

Additionally read this and this.



来源:https://stackoverflow.com/questions/441293/linqtosql-and-the-exception-executereader-requires-an-open-and-available-conne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!