locked
System.ObjectDisposedException: Safe handle has been closed RRS feed

  • Question

  • Hi All,

    I have been struggling on a similar issue as “https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2e98ec85-9ce0-452c-89c4-3cb6c4167590/systemobjectdisposedexception-safe-handle-has-been-closed-while-trying-to-begin-a-transaction?forum=sqldatabaseengine” in a web application based on .net framework 2.0 and sql server 2008 R2. the exception happened about 3 times per month since 2011, and when it happens, no one could connect to the web site anymore. Here is the stack trace of the error.

    at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)     
    at SNINativeMethodWrapper.SNIPacketReset(SafeHandle pConn, IOType ioType, SafeHandle packet)     
    at System.Data.SqlClient.TdsParserStateObject.WriteSni()     
    at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush()     
    at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)     
    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.ExecuteScalar()     
    at System.Data.SqlClient.SqlCommand.ExecuteScalar()     
    at TNSSmartNetwork.SPS.Data.SystemEventLog.EventLogEntry.Add(GenericPrincipal CurrentPrincipal)     
    at TNSSmartNetwork.SPS.Web.Shell.Global.Session_Start(Object sender, EventArgs e)     
    at System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e)     
    at System.Web.SessionState.SessionStateModule.CompleteAcquireState()     
    at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)     
    at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    I noticed the bug filed on the Microsoft Connect had been fixed, but it does not mention the reason and which version of .net framework it is fixed.

    https://connect.microsoft.com/VisualStudio/feedback/details/779588/safe-handle-objectdisposedexception-sqltransaction-dispose

    Appreciated if you could provide more details.


    julian wu

    Wednesday, February 4, 2015 6:27 PM

Answers

  • To get the access to the fix, you would need to open a case with Microsoft. But since the Connect item was closed in 2013, I would guess that the fix is .NET 4.6 which ships with VS2015.

    By the way, this forum is for engine issues with SQL Server. You should have posted to a .NET forum.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Wednesday, February 4, 2015 10:48 PM

All replies

  • To get the access to the fix, you would need to open a case with Microsoft. But since the Connect item was closed in 2013, I would guess that the fix is .NET 4.6 which ships with VS2015.

    By the way, this forum is for engine issues with SQL Server. You should have posted to a .NET forum.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Wednesday, February 4, 2015 10:48 PM
  • Hi julian,

    As the connect item indicates, the issue is due to .Net Framework. For quick and accurate answer, I would like to recommend you post the question in the .NET Framework  forum at https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=netdevelopment . It is appropriate and you can get better help.


    Thanks,
    Lydia Zhang


    If you have any feedback on our support, please click here.


    Lydia Zhang
    TechNet Community Support


    Thursday, February 5, 2015 3:41 AM