1

连接到网站并保持空闲 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
     }
}

我不知道,为什么我得到那个例外。我尝试了所有的可能性。没有任何帮助。我真的很震惊。如果有人知道,请告诉您的意见从这个例外中出来

提前致谢。

4

1 回答 1

0

我认为您的会话超时。

尝试增加会话超时:

http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.timeout.aspx

于 2013-02-21T20:34:16.693 回答