0

鉴于下面的类,在 Visual Studio 中启动网站在调用时会出现以下错误home/index(这实际上是内部异常)。

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);
    }
}

基本控制器

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);
    }
}
4

1 回答 1

1

这开始是作为一个评论,因为它更多的是一个建议而不是一个解决方案,但根据响应、个人经验,这个看似随机/每隔一个季度左右在本地发生的事件以及互联网搜索的结果,重新启动似乎可以解决这个问题问题多半。

从服务器接收结果时发生传输级错误

http://www.garrypassarella.co.uk/2011/05/12/a-transport-level-error-has-occurred-when-receiving-results-from-the-server-provider-shared-memory-provider-错误0-句柄无效/

http://www.soulsolutions.com.au/Blog/tabid/73/EntryId/666/A-transport-level-error-has-occurred.aspx

共识集中在内存管道的共享性质上,并被其他一些导致错误的后台进程赶上,直到执行系统重新启动。

于 2012-11-07T14:08:47.590 回答