Global Data Management Forum

Expand all | Collapse all

IBM.Data.DB2.Core - AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

  • 1.  IBM.Data.DB2.Core - AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    Posted Wed May 12, 2021 03:05 PM
    I'm getting the following error when opening a connection DB2Connection. I'm using IBM.Data.DB2.Core 3.1.0.400 in a netcoreapp3.1 web app in Azure. We finally figured out how to tunnel connections from a web app in Azure to an on-prem iSeries AS/400 server. Now I'm getting this. It works on my machine™, but not in Azure. I confirmed the web app is running in x64 and all projects are built in x64. Is this a networking issue?

    Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    at IBM.Data.DB2.Core.UnsafeNativeMethods+DB232.SQLConnectADONET(IntPtr, IntPtr ByRef, IBM.Data.DB2.Core.DB2NmpSetiInfo*, IntPtr ByRef, IBM.Data.DB2.Core.DB2SQLConnectADONETParams ByRef)
    at IBM.Data.DB2.Core.UnsafeNativeMethods+DB232.SQLConnectADONET(IntPtr, IntPtr ByRef, IBM.Data.DB2.Core.DB2NmpSetiInfo*, IntPtr ByRef, IBM.Data.DB2.Core.DB2SQLConnectADONETParams ByRef)
    at IBM.Data.DB2.Core.DB2ConnPool+DB2ConnWrapper.Open(System.String, System.Data.IsolationLevel, IBM.Data.DB2.Core.DB2Connection, Int32 ByRef, Int32 ByRef)
    at IBM.Data.DB2.Core.DB2ConnPool.Open(IBM.Data.DB2.Core.DB2Connection, System.String ByRef, DB2ConnSettings ByRef, System.Object ByRef)
    at IBM.Data.DB2.Core.DB2Connection.Open()
    at System.Data.Common.DbConnection.OpenAsync(System.Threading.CancellationToken)
    at Dapper.SqlMapper.TryOpenAsync(System.Data.IDbConnection, System.Threading.CancellationToken)
    at Dapper.SqlMapper+<QueryAsync>d__33`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Dapper.SqlMapper+<QueryAsync>d__33`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]](<QueryAsync>d__33`1<System.__Canon> ByRef)
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Dapper.SqlMapper+<QueryAsync>d__33`1[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]](<QueryAsync>d__33`1<System.__Canon> ByRef)
    at Dapper.SqlMapper.QueryAsync[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Data.IDbConnection, System.Type, Dapper.CommandDefinition)
    at Dapper.SqlMapper.QueryAsync[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Data.IDbConnection, System.String, System.Object, System.Data.IDbTransaction, System.Nullable`1<Int32>, System.Nullable`1<System.Data.CommandType>)


    ------------------------------
    John Rummell
    ------------------------------

    #DataManagementGlobal
    #DataServerDrivers


  • 2.  RE: IBM.Data.DB2.Core - AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    Posted Thu May 13, 2021 04:28 PM
    Hi John,

    May be this might help you resolve your issue.
    I have found this from following link:
    Q: Getting an Access Violation Exception when connecting to IBM i and Db2 databases from Azure. Is it a known issue?
      It is fixed in version 3.1.0.400 of Db2 .NET Core. The fix is also available in Db2 .NET 5 package. In addition to using the latest packages, please set the environment variable DB2_COMMON_APP_DATA_PATH to a writable location on Azure environment with sufficient permissions to write.

    https://community.ibm.com/community/user/hybriddatamanagement/blogs/michelle-betbadal1/2020/04/29/frequently-asked-questions-about-ibm-db-net-core-p


    ------------------------------
    Deepak Softwares
    ------------------------------



  • 3.  RE: IBM.Data.DB2.Core - AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Best Answer

    Posted Tue May 18, 2021 11:11 AM
    Edited by System Fri January 20, 2023 04:10 PM
    That helps, although the FAQ answer could include more information. In order to set an environment variable in an Azure web app, you actually have to add an Application Setting under the Configuration tab.

    The following setting fixed this for me:

    Name: DB2_COMMON_APP_DATA_PATH
    Value: D:\home\site\wwwroot\App_Data




    ------------------------------
    John Rummell
    ------------------------------