Asp.net mvc 4 问题:SQL Azure连接已断开。重新连接并访问实体对象后,发生错误

Asp.net mvc 4 问题:SQL Azure连接已断开。重新连接并访问实体对象后,发生错误,asp.net-mvc-4,entity-framework-5,azure-sql-database,Asp.net Mvc 4,Entity Framework 5,Azure Sql Database,连接到网站并保持空闲30分钟,然后试图访问实体,我得到以下错误 实体框架执行命令定义时出错。有关详细信息,请参见内部异常。内部异常{“无效的对象名'dbo.TableName'。} 示例代码 Static Class Azure { public static CrmEntities ConnectCustomerEntity() { CrmEntities customerEntity = null; policy.ExecuteAction(() =

连接到网站并保持空闲30分钟,然后试图访问实体,我得到以下错误

实体框架执行命令定义时出错。有关详细信息,请参见内部异常。内部异常{“无效的对象名'dbo.TableName'。}

示例代码

Static Class Azure
{
 public static CrmEntities ConnectCustomerEntity()
    {
        CrmEntities customerEntity = null;
        policy.ExecuteAction(() =>
           {
               try
               {
                   var shardId = GetShardId();

                   customerEntity = new CrmEntities(ConnectionStringCustomerDB());
                   string federationCmdText = @"USE FEDERATION Customer_Federation(ShardId =" + shardId + ") WITH RESET, FILTERING=ON";

                   customerEntity.Connection.Open();                     
                   customerEntity.ExecuteStoreCommand(federationCmdText);   
               }
               catch (Exception e)
               {
                  customerEntity.Connection.Close();
                  SqlConnection.ClearAllPools();
                   //throw e;
               } 
           });
        return customerEntity;
    }

 public static CrmEntities DBConnect(CrmEntities _db)
    {
     try{
        if (_db == null)
            _db = Azure.ConnectCustomerEntity();
        if ((_db.Connection.State == ConnectionState.Broken) || (_db.Connection.State == ConnectionState.Closed))
        {               
            SqlConnection.ClearAllPools();
            _db = Azure.ConnectCustomerEntity();
        }
    else
        { //This code is to find out any issues in connection pool database connection
      string sqlCmdText = @"select top 1 Id from Project";
            _db.ExecuteStoreCommand(sqlCmdText);
        }
        }
  catch (Exception ex)
        {
            _db.Connection.Close();
            SqlConnection.ClearAllPools();
            _db = Azure.ConnectCustomerEntity();
        }
        return _db;
}

}
Mvc控制器。下面的代码是我在30分钟后得到的异常

 public class FilterController : Controller
{  
public ActionResult GetFilters(string entityName,string typeFilter)
    {
       _crmEntities=Azure.DBConnect(_db);
        var query = _db.FilterFields.Where(filter => filter.TableId == tableId).ToList();  // Here I am getting that exception
     }
}
我不知道,为什么我会得到那个例外。我尝试了所有的可能性。没有任何帮助。我真的被这个打动了。如果有人知道,请把你的观点从这个例外中说出来


提前谢谢。

我想您的课程已经结束了

尝试增加会话超时:


Kash,我根本没有使用任何会话。它只与SQLAzure连接相关。