Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2 with .NET Core 2.1

Tags:

.net-core

db2

I installed IBM.Data.DB2.Core Version (1.2.2.100) with Visual Studio 2017 & .Net Core 2.1. I was trying to test simple DB2 (z/OS server) connection and getting the below error. Our DB2 Server type is OS390 and version is 11.

ERROR [42968] [IBM] SQL1598N An attempt to connect to the database server failed because of a licensing problem.

 using (DB2Connection con = new DB2Connection("Server=xxxx.xxxx.com:446;Database=XXXX;UID=XXXXXX;PWD=xxxxx"))
            {
                try
                {
                    con.Open();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            } 

Also I copied the license file to .nuget\packages\ibm.data.db2.core\1.2.2.100\build\clidriver\license folder. I tried everything mentioned here: https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Instructions_for_downloading_and_using_DB2_NET_Core_provider_package?lang=en

Any thoughts?

like image 375
Yass Avatar asked Mar 06 '23 01:03

Yass


1 Answers

Spent a few hours on this and here is what worked for me using current latest version of the package 1.3.0.100 and a valid DB2 11.1 license I already had installed. I suspect this approach will work on 1.1 and 1.2 as well, assuming you have the license already.

Add the following block to your project file, adjusting the path for DB2License as necessary for your local setup:

  <ItemGroup>
    <DB2License Include="C:\ProgramData\IBM\DB2\{FOLDER NAME THAT VARIES BY INSTALL}\license\**\*.*"/>
  </ItemGroup>
  <Target Name="CopyFiles" AfterTargets="AfterBuild">
    <Copy SourceFiles="@(DB2License)" DestinationFolder="$(OutDir)\clidriver\license\" />
  </Target>

The important part seems to be that $(OutDir)\clidriver\license\ has all files necessary to represent a valid DB2 11.1+ license before your application runs. For me there were 3 files. For server build and release, a slightly more complex setup may be necessary to get the correct files to the expected location.


Here are other things I tried that did not seem to help for me, but may help for others:

  1. Some articles on IBM's site suggest adding %userprofile%\.nuget\packages\IBM.Data.DB2.Core\<version>\build\clidriver\bin or %userprofile%\.nuget\packages\IBM.Data.DB2.Core\<version>\build\clidriver\license to your PATH environment variable. This seems to be completely unnecessary.
  2. Other articles or forum posts suggest copying your license files to the nuget package license folder %userprofile%\.nuget\packages\IBM.Data.DB2.Core\<version>\build\clidriver\license. This worked, but isn't ideal since it needs to be done on each machine after nuget package restore and then re-done if you change versions of the nuget package later on. And of course none of the places mentioning "hey just copy the license to this path" specified the default directory that contains your existing license: C:\ProgramData\IBM\DB2\{FOLDER NAME THAT VARIES BY INSTALL}\license\.
like image 173
David Moeller Avatar answered Apr 27 '23 12:04

David Moeller