Question

Given the classes below, firing up the website in Visual Studio gives me the following error when home/index is called (this is actually the inner exception).

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)

However if I publish the exact same code locally and hit the site using WebMatrix, it works fine.

I'm using SQL Server 2008 Express too if that makes a difference. Please advise if any more information is needed.

Controller

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 (Entities is an EF edmx class)

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);
    }
}
Was it helpful?

Solution

This started off as a comment as it was more of a suggestion than a solution, but based on the response, personal experience with this seemingly random/every other quarter or so occurrences locally and the results of a internet search, rebooting seems to fix this problem more often than not.

A transport-level error has occurred when receiving results from the server

http://www.garrypassarella.co.uk/2011/05/12/a-transport-level-error-has-occurred-when-receiving-results-from-the-server-provider-shared-memory-provider-error-0-the-handle-is-invalid/

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

The consensus is centered around the shared nature of the memory pipe and getting caught up with some other background process(es) that cause an error until a system reboot is performed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top