【问题标题】:ASP.Net MVC 3 System.Data.SqlClient.SqlException Timeout expiredASP.Net MVC 3 System.Data.SqlClient.SqlException 超时已过期
【发布时间】:2012-08-22 11:26:08
【问题描述】:

我正在使用 Entity Framework 4.1 开发一个 ASP.Net MVC 3 Web 应用程序。我最近将应用程序上传到了我的测试服务器,我注意到 ELMAH 发送的错误电子邮件指出

System.Data.SqlClient.SqlException 超时已过期。超时时间 在操作完成之前已经过去,或者服务器没有 回应。

下面显示了我的一些代码。

控制器

public ActionResult VerifyEmail(int uid, string vid)
{
    var userList = _userService.VerifyEmail(uid,vid).ToList();
}

服务

public IList<User> VerifyEmail(int uid, string emailvcode)
{
    return _uow.User.Get(u => u.userID == uid && u.emailVerificationCode == emailvcode).ToList();
}

工作单元

 public class UnitOfWork : IUnitOfWork, IDisposable
 {
        readonly LocumEntities _context = new LocumEntities();

        private GenericRepository<User> _user = null;

        public IGenericRepository<User> User
        {
            get
            {
                if (_user == null)
                {
                    _user = new GenericRepository<User>(_context);
                }
                return _user;
            }

        }

  }

通用存储库

public IList<TEntity> Get(Expression<Func<TEntity, bool>> filter = null,Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,string includeProperties = "")
{
    IQueryable<TEntity> query = dbSet;

    if (filter != null)
    {
        query = query.Where(filter);
    }

    foreach (var includeProperty in includeProperties.Split
        (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
    {
        query = query.Include(includeProperty);
    }

    if (orderBy != null)
    {
        return orderBy(query).ToList();
    }
    else
    {
        return query.ToList();
    }
}

Timeout 错误有时会在 Service 方法中的行尝试执行时发生

return _uow.User.Get(u => u.userID == uid && u.emailVerificationCode == emailvcode).ToList();

此错误并非每次都发生,只是偶尔发生,但是,我不明白为什么此查询将返回用户列表或 NULL 列表。

谁能从我的代码中发现为什么会发生这种情况?

任何反馈都将不胜感激,因为我不知道为什么会发生这种情况。

谢谢。

【问题讨论】:

    标签: asp.net-mvc-3 sql-server-2008 entity-framework-4.1 timeout


    【解决方案1】:

    尝试增加连接字符串中的超时属性。还要运行 SQL Server Profiler 以查看为您的查询生成了多少 SQL,因为查询可能会返回大量数据,从而导致超时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 2011-08-20
      • 1970-01-01
      • 2011-03-29
      • 2015-02-10
      相关资源
      最近更新 更多