1
連接到網站並保持閒置30分鐘,然後試圖訪問實體我收到以下錯誤。問題:SQL Azure連接中斷。重新連接並訪問實體對象後,發生錯誤
實體框架執行命令定義時發生錯誤。詳情請參閱內部例外。內部異常{「無效的對象名稱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
}
}
我不知道,爲什麼我得到這個例外。我嘗試了所有可能性。沒什麼幫助。我真的很震驚。如果有人知道請告訴您的意見,從這種異常出來
在此先感謝。
卡什,我沒有使用任何會議都沒有。它只與SQLAzure連接有關。 – sivaL 2013-02-27 12:46:11