none
Attempted to read or write protected memory on any SQL connection open after installing .Net Framework 4.5.1 (ADO.NET) RRS feed

  • Question

  • Hi, ive installed VS2013 RTM lately and discovered that all SQL connects stopped working. They all die with the exception below. All means any program that opens an SQL connection via ADO.NET dies. This includes SQL Managment Studio, Visual Studio or any other program. 

    To track it down ive created an application with the following code which reproduces that error on "con.Open".

    var con = new SqlConnection("Server=Server;Database=Foobar;User=Foobar");
    con.Open();

    So Ive uninstalled all which have todo with SQL or Dotnet.

    Ive installed .Net 4.0 - works
    Ive installed .Net 4.5 - works
    Ive installed .Net 4.5.1 - error

    My configuration is Windows 7 Enterprise 64bit. Everything other then SQL connection, works fine. Even complex .Net applications working when they dont use SQL connections.

    I have absolutely no idea how to fix that, so please give me a hint!

    Full error stacktrace of the app above:

    Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
       at System.Data.SqlClient.SNIHandle.ReleaseHandle()
       at System.Runtime.InteropServices.SafeHandle.InternalDispose()
       at System.Data.SqlClient.TdsParserStateObject.Dispose()
       at System.Data.SqlClient.TdsParser.Disconnect()
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginFailure()
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, Stri
    ng newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, O
    bject providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData r
    econnectSessionData)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConn
    ectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConne
    ctionPoolKey poolKey, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection
    )
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean o
    nlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbCon
    nectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions
    , DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletio
    nSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()

    Thursday, November 7, 2013 12:33 PM

Answers

  • Our team was also experiencing this issue.

    We were able to fix it by running this from cmd: netsh winsock reset 

    After rebooting, everything worked as expected.
    • Marked as answer by Steve Wagner Monday, November 25, 2013 11:11 AM
    Friday, November 22, 2013 9:55 PM

All replies

  • Hi Steve,

    Usually when we use unmanaged code may throw this exception. Uncovering and correcting memory issue in managed applications can be difficult. Memory issues manifest themselves in different ways. I have two ways maybe could solve your issue. Please try and let me know the result.

    The first way, go into the Build properties of your projects (Project/properties/Build Tab) and changed the Platform Target to "x86". Then run the application again.

    The second way, try to close or uninstall when allowed your Anti-Virus application. The exception was gone.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 8, 2013 2:40 AM
    Moderator
  • Hi,

    today i install Visual Studio 2013 Premium (includes .Net Framework 4.5.1) on my machine.

    Environment: Windows 7 x64 Ultimate

    I got the same error like Steve when calling .Open of SQLConnection class in our business application.

    After removing .4.5.1 and installing .Net Framework .4.5 everthing works fine. Setting all projects so x86 does not fix the problem.

    Regards

    Dominik

    Monday, November 11, 2013 1:54 PM
  • What I dont have tried yet is to completely uninstall our Virus Scanner (Avira). Ive deactivated it already without success.

    What I have forgotten to mention is that my colleague has the same problem.
    Monday, November 11, 2013 1:59 PM
  • Hi All,

    I have found that there is a new feature in .NET Framework 4.5.1 about ADO. NET, I think there may be something wrong with this feature. Please refer to this page and see the information about it. http://blogs.msdn.com/b/dotnet/archive/2013/06/26/announcing-the-net-framework-4-5-1-preview.aspx.

    Someone has posted a thread on Microsoft Connect to report this issue, I recommend you vote on it. http://connect.microsoft.com/VisualStudio/feedback/details/807376/fail-to-connect-the-remote-db-server.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 12, 2013 1:50 AM
    Moderator
  • Our team was also experiencing this issue.

    We were able to fix it by running this from cmd: netsh winsock reset 

    After rebooting, everything worked as expected.
    • Marked as answer by Steve Wagner Monday, November 25, 2013 11:11 AM
    Friday, November 22, 2013 9:55 PM
  • That seems to work here too. Thanks very much for figuring this out.
    Monday, November 25, 2013 11:12 AM
  • We get this from the microsoft support:

    open cmd.exe and run command "netsh winsock reset catalog"

    We habe analyse the problem an get to rhe point that in our environment the Avira Internet Security Version 12 cause this issue. After updating to the lastet version everything works fine also without reset winsock catalog.

    Other programms like "Watchguard" can also cause this exceptions.

    Tuesday, November 26, 2013 10:28 AM
  • I followed your details and changing the Platform Target to "x64" ... issue resolved.

    Tuesday, April 8, 2014 6:47 PM