Topic
  • 15 replies
  • Latest Post - ‏2019-04-17T20:08:15Z by TysonW
JRDNucor
JRDNucor
9 Posts

Pinned topic IBM.Data.DB2 System.AccessViolationException

‏2018-02-16T14:32:40Z |

We are trying to get up and running on the DB2 cloud driver for Azure that is posted here: https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/IBMDBADONETAZURECLOUDDRIVER?lang=en .  I currently have this code able to connect to our iSeries DB2 from my computer running VS2017 and Windows 10.  We also have purchased a DB2 connect unlimited for iSeries license.  Everything works great locally but when we publish to Azure, we get a unsafe code exception when the connect method is called and our W3WP process terminates.  We currently connect to the iSeries from Azure using a hybrid connection manager.  Below is the exception and stack trace that we are getting.  Has anyone encountered this before or able to help?  We have tried the following versions of the nuget package 11.1.2020.4 and 11.1.1010.4161.

 

 

Application: w3wp.exe

Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.AccessViolationException at IBM.Data.DB2.UnsafeNativeMethods+DB232.SQLConnectADONET(IntPtr, IntPtr ByRef, IBM.Data.DB2.DB2NmpSetiInfo*, IntPtr ByRef, IBM.Data.DB2.DB2SQLConnectADONETParams ByRef) at IBM.Data.DB2.DB2ConnPool+DB2ConnWrapper.Open(System.String, System.Data.IsolationLevel, IBM.Data.DB2.DB2Connection, Int32 ByRef, Int32 ByRef) at IBM.Data.DB2.DB2ConnPool.Open(IBM.Data.DB2.DB2Connection, System.String ByRef, DB2ConnSettings ByRef, System.Object ByRef) at IBM.Data.DB2.DB2Connection.Open() at System.Data.Common.DbConnection.OpenAsync(System.Threading.CancellationToken) at System.Data.Common.DbConnection.OpenAsync() at NSAR.Contexts.As400Context+<QueryAs400Async>d__9.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon ByRef) at NSAR.Contexts.As400Context.QueryAs400Async(System.String, System.Action`1<IBM.Data.DB2.DB2ParameterCollection>) at NSAR.Contexts.As400Context+<GetHoldsAsync>d__7.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon ByRef) at NSAR.Contexts.As400Context.GetHoldsAsync(System.Collections.Generic.List`1<System.String>) at NSAR.Services.HoldService+<GetHoldsAsync>d__3.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Start[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.__Canon ByRef) at NSAR.Services.HoldService.GetHoldsAsync(System.Collections.Generic.List`1<System.String>) at NSAR.Services.ProcessSnapshotService+<GetProcessSnapshotDetails>d__7.MoveNext() at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run() at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, System.Object, System.Threading.Tasks.Task ByRef) at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TrySetResult(System.__Canon) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SetResult(System.__Canon) at NSAR.Contexts.Db2CopyContext+<GetCoilProcessHistories>d__14.MoveNext() at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run() at System.Web.Util.SynchronizationHelper.SafeWrapCallback(System.Action) at System.Threading.Tasks.Task.Execute() at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef) at System.Threading.Tasks.Task.ExecuteEntry(Boolean) at System.Threading.ThreadPoolWorkQueue.Dispatch()

Updated on 2018-02-16T14:41:13Z at 2018-02-16T14:41:13Z by JRDNucor
  • JRDNucor
    JRDNucor
    9 Posts
    ACCEPTED ANSWER

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-08-09T14:05:53Z  
    • alekz1287
    • ‏2018-08-09T00:14:42Z

    I am facing the same AccessViolationException when deploying to Azure. I've tried copying the license file (db2consv_ee.lic)  to every folder that makes sense and some that don't.

    We found that when deploying to Azure app service through a Azure on premise gateway, the license is not sent back to the IBM iSeries/AS400 system.  To work around this issue we were able to activate the license on the system directly by running the activate command.  Once you do this, you no longer need to put the license file on any client.  It has been a while since we fixed this but I believe that we followed this article:

     

    https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.licensing.doc/doc/t0057375.html

    I hope this helps!

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-02-20T16:37:27Z  

    Anyone from IBM?

  • pkarnam
    pkarnam
    13 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-02-26T06:45:01Z  
    • JRDNucor
    • ‏2018-02-20T16:37:27Z

    Anyone from IBM?

    Hi,

    Just for everyone's information:

    Client side license was not applied in the Azure environment hence System.AccessViolation error was coming up.

    We have made a note of it.

    For z/OS and i-series servers, license is validated before the connecting to the server.

    Hence even in Azure environment license must be applied either at the client side or at the server side.

    The issue was resolved after applying the server side license.

    Thanks and Regards,

    Prashanth Karnam.

  • paul.ivanov
    paul.ivanov
    2 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-07-11T19:54:48Z  
    • pkarnam
    • ‏2018-02-26T06:45:01Z

    Hi,

    Just for everyone's information:

    Client side license was not applied in the Azure environment hence System.AccessViolation error was coming up.

    We have made a note of it.

    For z/OS and i-series servers, license is validated before the connecting to the server.

    Hence even in Azure environment license must be applied either at the client side or at the server side.

    The issue was resolved after applying the server side license.

    Thanks and Regards,

    Prashanth Karnam.

    Hi  @pkarnam,

    I was wondering how you were able to apply the license to the server and which type of license you needed in order to make it work. Do you have those details?

     

    Thanks and Kind Regards,

    Paul Ivanov

  • alekz1287
    alekz1287
    7 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-08-09T00:14:42Z  

    I am facing the same AccessViolationException when deploying to Azure. I've tried copying the license file (db2consv_ee.lic)  to every folder that makes sense and some that don't.

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-08-09T14:05:53Z  
    • alekz1287
    • ‏2018-08-09T00:14:42Z

    I am facing the same AccessViolationException when deploying to Azure. I've tried copying the license file (db2consv_ee.lic)  to every folder that makes sense and some that don't.

    We found that when deploying to Azure app service through a Azure on premise gateway, the license is not sent back to the IBM iSeries/AS400 system.  To work around this issue we were able to activate the license on the system directly by running the activate command.  Once you do this, you no longer need to put the license file on any client.  It has been a while since we fixed this but I believe that we followed this article:

     

    https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.licensing.doc/doc/t0057375.html

    I hope this helps!

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-08-09T14:06:51Z  

    Hi  @pkarnam,

    I was wondering how you were able to apply the license to the server and which type of license you needed in order to make it work. Do you have those details?

     

    Thanks and Kind Regards,

    Paul Ivanov

    DB2Connect unlimited edition activated on the iSeries with this: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.licensing.doc/doc/t0057375.html

  • alekz1287
    alekz1287
    7 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-08-09T16:17:06Z  
    • JRDNucor
    • ‏2018-08-09T14:05:53Z

    We found that when deploying to Azure app service through a Azure on premise gateway, the license is not sent back to the IBM iSeries/AS400 system.  To work around this issue we were able to activate the license on the system directly by running the activate command.  Once you do this, you no longer need to put the license file on any client.  It has been a while since we fixed this but I believe that we followed this article:

     

    https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.licensing.doc/doc/t0057375.html

    I hope this helps!

    Very helpful, JRDNucor! Thank you for taking the time to reply. 

    The link provided refers to the "Unlimited Edition". Because we are using the "Enterprise Edition" I don't think we can activate the license on the server. 

    IBM provides an example of a connection to DB2 from Azure. In the example, they upload their client license to Azure, but they don't mention how they expose the database to the cloud. We - like you - have used a Hybrid Connection Manager to "punch through" to the on-premises network. If the hybrid connection doesn't pass along the license, then they must be exposing their network some other way.

    We'll keep digging, but your response has definitely pointed us in the right direction.

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2018-08-09T17:18:03Z  
    • alekz1287
    • ‏2018-08-09T16:17:06Z

    Very helpful, JRDNucor! Thank you for taking the time to reply. 

    The link provided refers to the "Unlimited Edition". Because we are using the "Enterprise Edition" I don't think we can activate the license on the server. 

    IBM provides an example of a connection to DB2 from Azure. In the example, they upload their client license to Azure, but they don't mention how they expose the database to the cloud. We - like you - have used a Hybrid Connection Manager to "punch through" to the on-premises network. If the hybrid connection doesn't pass along the license, then they must be exposing their network some other way.

    We'll keep digging, but your response has definitely pointed us in the right direction.

    From our research, I believe the way the license is validated on the client is conflicting with how azure app service makes hybrid connections.  When we used wire shark to look at the packets from the app to the iSeries on our network vs azure, we noticed that the Azure version does not send certain DRDA commands that are being sent when the app is running in visual studio.  What I believe was happening is that to make a hybrid connection work, it seems that Microsoft makes a sort of host file entry on the Azure VM.  This entry seems to route traffic meant for your on premise database to a service running on localhost.  It seems the iSeries driver has an issue with this because it is expecting that it is sending a command to the iSeries server but it is actually sending it to local host.  When this happens, it tries to access things on localhost within the Azure app service VM but local host is locked down permissions wise and thus you get a SystemAccessViolation exception.  I think the example on their website is not using a hybrid connection, so they have no problems putting the file on the client.  I also thought that the unlimited edition license is the only one that you can get now for web site type access.  If switching your license to a unlimited edition license is not possible, I would recommend trying to use a azure app service VPN instead of the hybrid connection.  This is all mostly speculation on what is really causing the problem with hybrid connections but I thought it might help you save some time.  I think that for Azure App service connections using db2 connect for i over hybrid connection to work, IBM would have to release an update to the Nuget package that accesses the license file in another way.

  • TysonW
    TysonW
    3 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2019-04-16T20:29:13Z  
    • JRDNucor
    • ‏2018-08-09T17:18:03Z

    From our research, I believe the way the license is validated on the client is conflicting with how azure app service makes hybrid connections.  When we used wire shark to look at the packets from the app to the iSeries on our network vs azure, we noticed that the Azure version does not send certain DRDA commands that are being sent when the app is running in visual studio.  What I believe was happening is that to make a hybrid connection work, it seems that Microsoft makes a sort of host file entry on the Azure VM.  This entry seems to route traffic meant for your on premise database to a service running on localhost.  It seems the iSeries driver has an issue with this because it is expecting that it is sending a command to the iSeries server but it is actually sending it to local host.  When this happens, it tries to access things on localhost within the Azure app service VM but local host is locked down permissions wise and thus you get a SystemAccessViolation exception.  I think the example on their website is not using a hybrid connection, so they have no problems putting the file on the client.  I also thought that the unlimited edition license is the only one that you can get now for web site type access.  If switching your license to a unlimited edition license is not possible, I would recommend trying to use a azure app service VPN instead of the hybrid connection.  This is all mostly speculation on what is really causing the problem with hybrid connections but I thought it might help you save some time.  I think that for Azure App service connections using db2 connect for i over hybrid connection to work, IBM would have to release an update to the Nuget package that accesses the license file in another way.

    Hi,

    We are setting up a Azure connections and have followed the following instructions. https://docs.microsoft.com/en-us/azure/connectors/connectors-create-api-db2 We are unable to get the connection. I have contacted IBM support and they said to post it here. Does anyone have directions on where to install the "nuget"? The gateway?.

  • GinaMcq
    GinaMcq
    1 Post

    Re: IBM.Data.DB2 System.Access Power System setup

    ‏2019-04-16T20:44:32Z  

     When setting up the Power System to accept the Azure connection I wanted to verify the user profile settings, directory entry, and anything else I may be missing, does anyone have their setup I can compare against to see what I may be missing for Azure.... Thanks for anyone's help

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2019-04-16T21:42:55Z  
    • TysonW
    • ‏2019-04-16T20:29:13Z

    Hi,

    We are setting up a Azure connections and have followed the following instructions. https://docs.microsoft.com/en-us/azure/connectors/connectors-create-api-db2 We are unable to get the connection. I have contacted IBM support and they said to post it here. Does anyone have directions on where to install the "nuget"? The gateway?.

    NuGet is a package manager for .Net projects and allows you to pull in packages of reusable code from 3rd parties and Microsoft.  It looks like the link you have posted is not using custom .Net code so you would not be using NuGet for anything.  The Azure data gateway is a piece of software that allows a cloud service to communicate with an on premise database without using a VPN or direct network connection.  You would need to install that software on a Windows server that has the ability to communicate with your iSeries over TCP/IP.

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.Access Power System setup

    ‏2019-04-16T21:45:09Z  
    • GinaMcq
    • ‏2019-04-16T20:44:32Z

     When setting up the Power System to accept the Azure connection I wanted to verify the user profile settings, directory entry, and anything else I may be missing, does anyone have their setup I can compare against to see what I may be missing for Azure.... Thanks for anyone's help

    If you follow the links I have posted in the thread above, it should get you setup.  We followed the example .Net project provided by ibm and the link I posted above to install the license on our iSeries machine.  In terms of user settings, you will need an account on the iSeries with database access.

  • TysonW
    TysonW
    3 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2019-04-17T15:44:11Z  
    • JRDNucor
    • ‏2019-04-16T21:42:55Z

    NuGet is a package manager for .Net projects and allows you to pull in packages of reusable code from 3rd parties and Microsoft.  It looks like the link you have posted is not using custom .Net code so you would not be using NuGet for anything.  The Azure data gateway is a piece of software that allows a cloud service to communicate with an on premise database without using a VPN or direct network connection.  You would need to install that software on a Windows server that has the ability to communicate with your iSeries over TCP/IP.

    Just to verify,

    Our web designers are asking to connect to our on-premise power8 box. He is using "Azure App Service running a .NET 4.7.2 Web Application" to design our website. He will be pulling product information from our Power8 box and processing orders to it. Will he be able to use the Azure Gateway to accomplish this?

    Keep in mind that this is what was suggested to us so I have already put in the Azure Gateway and we can see request hitting the power8 box, but no data is going back to the Azure logic app. it seems to time out. Any suggestions on how to troubleshoot this?

  • JRDNucor
    JRDNucor
    9 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2019-04-17T18:55:10Z  
    • TysonW
    • ‏2019-04-17T15:44:11Z

    Just to verify,

    Our web designers are asking to connect to our on-premise power8 box. He is using "Azure App Service running a .NET 4.7.2 Web Application" to design our website. He will be pulling product information from our Power8 box and processing orders to it. Will he be able to use the Azure Gateway to accomplish this?

    Keep in mind that this is what was suggested to us so I have already put in the Azure Gateway and we can see request hitting the power8 box, but no data is going back to the Azure logic app. it seems to time out. Any suggestions on how to troubleshoot this?

    The short answer I have is that yes this should work as it is what we are doing.  I would make sure the hybrid connection is setup correctly in azure.  I would also make sure the correct ports are open for the Azure gateway in your network.  I would also verify that you have a license for the NuGet package to connect from IBM.  To connect to an iSeries machine, you need a DB2 connect for i unlimited license.  We installed this on our iSeries.  You can read about that further up in the thread.  Other than the license, we followed the examples as given and everything worked.

  • TysonW
    TysonW
    3 Posts

    Re: IBM.Data.DB2 System.AccessViolationException

    ‏2019-04-17T20:08:15Z  
    • JRDNucor
    • ‏2019-04-17T18:55:10Z

    The short answer I have is that yes this should work as it is what we are doing.  I would make sure the hybrid connection is setup correctly in azure.  I would also make sure the correct ports are open for the Azure gateway in your network.  I would also verify that you have a license for the NuGet package to connect from IBM.  To connect to an iSeries machine, you need a DB2 connect for i unlimited license.  We installed this on our iSeries.  You can read about that further up in the thread.  Other than the license, we followed the examples as given and everything worked.

    I'm sure we have DB2 licensing because we are using it on our current on-prem windows based webserver running IIS. We have unlimited 85 DB2 connections. What is the NuGet package license? What does it do?

     

    As I mentioned, we can see the connection hitting the Power8box but it times out in Azure.  How did you get past the schema setup? We think that might have something to do with our issue. Azure does not have an entry for the schema when setting up the API Connection. On our live local DB2 connection, the connection string has a schema that points to the library where the data is stored. We need to do the same thing in the azure piece.

     

    I have included our live connection string that is currently working on our webserver. It uses a schema to access the correct library.

    <add connectionString="Server=xxx.xxx.xxx:446;Database=Bxxxxxxx;UID=someuid;PWD=somepassword;CurrentSchema=wedb;Connection Lifetime=60;Max Pool Size=100;Min Pool Size=10; QueryTimeout=0" name="AS400" providerName="IBM.Data.DB2" />

     

    Thanks!
     

    Updated on 2019-04-17T20:12:24Z at 2019-04-17T20:12:24Z by TysonW