DB2 with .NET Core 2.1

2019-08-07 11:23发布

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?

标签: db2 .net-core
2条回答
唯我独甜
2楼-- · 2019-08-07 12:12

IBM DB2 Nuget package for .net core version 1.1 & 1.2 comes with DB2 Driver version 11. These two packages doesn't support if you have DB2 version less than 11. Here is the steps to resolve this issue.

  1. Install IBM DB2 Nuget package version 1.0
  2. Update your environment PATH variable with 1.0 installation path
  3. Remove/Un-install any other DB2 driver installed on your machine
  4. Close your Visual studio version and reopen it, it will work without any issue.

Also, 1.0 version doesn't require the license file. Hope this helps.

查看更多
淡お忘
3楼-- · 2019-08-07 12:12

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\.
查看更多
登录 后发表回答