考慮到下面的類,在調用home/index
(這實際上是內部異常)時,在Visual Studio中啓動網站時出現以下錯誤。ObjectContext Dev中出錯但未發佈時
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The handle is invalid.)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
但是,如果我在本地發佈完全相同的代碼,並使用WebMatrix中擊中的部位,它工作正常。
我正在使用SQL Server 2008 Express,如果這樣做有所作爲。請告知是否需要更多信息。
控制器
public class HomeController : BaseController
{
public ActionResult Index()
{
var candidates = BusinessObj.AllOf<Candidate>().ToList();
return View(candidates);
}
}
BaseController
public class BaseController : Controller
{
protected ITestBusinessObject BusinessObj { get; set; }
public BaseController()
{
BusinessObj = new Business.TestBusinessObj();
}
}
TestBusinessObj(實體是一個EF EDMX類)
public class TestBusiness : ITestBusinessObject
{
private Entities DB = new Entities();
private string ContainerName = "Entities";
public IEnumerable<T> AllOf<T>() where T : class, new()
{
return DB.CreateObjectSet<T>(ContainerName.GetEntitySetName<T>());
}
private static string GetEntitySetName<T>(this string containerName) where T : new()
{
var name = new T().GetType().Name;
if (name.EndsWith("y"))
{
name = name.Substring(0, name.Length - 1) + "ies";
}
else
{
name = name + "s";
}
return string.Format("{0}.{1}", containerName, name);
}
}
可能是一個愚蠢的問題,但你是否因爲發生這個問題而重新啓動了你的機器? – Tommy
@Tommy我有和令人沮喪的是,它再次工作。這是幾個小時,我不會回來.. – glosrob
是的,當我做了一些周圍(並從個人經驗),似乎有時共享內存提供程序綁定一些後臺進程和重新啓動通常修復它。高興起來,再次工作。 – Tommy