Topic
  • No replies
Thomas62
Thomas62
2 Posts

Pinned topic Use DB2 in a mixed .net core / .net 4.7 project

‏2019-06-14T11:27:04Z | .net .net-core c# db2
We want to reuse our .net 4.7 library (C#) to Access a DB2 10.5 database from a new .net core 2.2 Project. Unfortunately I get errors if I open the connection:

 

> System.InvalidOperationException: "SQL1159 Initialization error with
> DB2 .NET Data Provider, reason code 2, tokens
> D:\Projekte\Main-Branch-IpIdentity\Services\InvoiceApi\InvoiceApi\bin\db2app64.dll,
> , Process Owner

 

The missing dll can be found in path under C:\Program Files\IBM\SQLLIB\BIN.
I copied all out of this directory to the project output directory and got:

 

> System.InvalidOperationException: "SQL1159 Initialization error with
> DB2 .NET Data Provider, reason code 10, tokens 0.0.0, 10.5.5, Process
> Owner:

 

I wrote a console project in .net core, calling a .net core dll with Access to DB2:

 

class Program
{
   static void Main(string[] args)
   {
      var count = DB2AccessCore.Db2Access.GetCount();
   }
}

 

namespace DB2AccessCore
{
   public class Db2Access
   {
      public static int GetCount()
      {
         var con = new DB2Connection("....");
         con.Open();
         var cmd = con.CreateCommand();
        cmd.CommandText = "SELECT COUNT(*) FROM data.abstimmfeldausschnitt";
        var a = cmd.ExecuteScalar();
        con.Close();
        return (int)a;
      }
   }
}

 
The example works fine, also if I use the same Code in a .net 4.7 console and dll. But I call the 4.7 dll from the core console I get a exception:

 

> System.AccessViolationException: "Attempted to read or write protected
> memory. This is often an indication that other memory is corrupt."

 

Sounds not good…
What do I wrong, or is it not possible with DB2 to mix between core and 4.7? Has anybody already done this?
Thanks for help!