2

I want to connect to a DB2 database on an IBM i 7.2 server from a Windows client machine using .NET Core 3.1. I installed IBM.Data.DB2.Core via NuGet, but it always throws this cryptic exception:

IBM.Data.DB2.Core.DB2Exception
  HResult=0x80004005
  Message=External component has thrown an exception.
  Source=IBM.Data.DB2.Core
  StackTrace:
   at IBM.Data.DB2.Core.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
   at IBM.Data.DB2.Core.DB2Connection.Open()
   at Dapper.SqlMapper.<QueryImpl>d__140`1.MoveNext() in /_/Dapper/SqlMapper.cs:line 1079
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 721
   at Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 648
   at SqlPerformanceTesting.Program.<Main>d__0.MoveNext() in C:\Users\mmarchese\Desktop\SqlPerformanceTesting\SqlPerformanceTesting\Program.cs:line 54

I think I need to install different drivers/software on my Windows client machine first. Right now, I have "IBM I Access Client Solutions" installed, but maybe I need something else instead such as "IBM Data Server Drivers?" And that requires a license, it seems? Do I also need to install something on the IBM server to go with it? Can someone spell it out for me or point me to a good guide? I haven't been able to find much myself. Like, "Here are the general steps:"

  1. Install software A on Windows client
  2. Install software B on IBM i server
  3. Install IBM.Data.DB2.Core on Windows client
  4. Do procedure C to configure Windows client
  5. Do procedure D to configure IBM server

Update:

If I specify a bad connection string, I get a different error. Since IBM.Data.DB2.Core includes a class for building valid connection strings, I assume my connection string is ok:

var connStringBld = new DB2ConnectionStringBuilder()
{
    Database = "myDb",
    UserID = "myUser",
    Password = "myPassword",
    Server = "myIp"
};
Console.WriteLine(connStringBld.ConnectionString);
// Database=myDb;User ID=myUser;Password=myPassword;Server=myIp
8
  • Strange Coincidence. Somebody this morning has same 0x80004005 on Android. It may be the file isn't found. Check with File Explorer and see dB2 database from machine where code is running. Commented Jul 13, 2020 at 17:26
  • @jdweng Yeah, I think a file (or many files) is missing, but I don't know which or how to resolve it. I think I must have skipped a required driver installation. Commented Jul 13, 2020 at 17:30
  • It could be the connection string. Commented Jul 13, 2020 at 17:34
  • Why are'nt you using "IBM.Data.DB2.iSeries" ? See ibm.com/support/pages/ibm-i-access-windows-net-data-provider , and get the "IBM DB2 for i .NET Provider Technical Reference" which is part of the IBM i Access for Windows Programmer's Toolkit, an optionally installed feature of the IBM i Access for Windows product. Commented Jul 13, 2020 at 17:45
  • @jdweng I don't think it's the connection string. See my update for more info. Commented Jul 13, 2020 at 17:52

1 Answer 1

0

I had the same problem but I only follow the next steps:

  • Install IBM.Data.DB2.Core (is ONLY for windows, if using in Linux, you must install IBM.Data.DB2.Core-lnx instead. Also installed cause I run it into Docker container).

  • Paste the licences files (of Windows) in my project located at {MyProject}/License folder. The licences are db2.consv.lic and db2ese.lic files

  • Also check that when I use the Nuget, a linked folder named "clidriver" is attached in the root project. I also verified that the location %userprofile%\.nuget\packages\ibm.data.db2.core\1.3.0.100\build\clidriver\license had the licence files.

  • Define DI in Startup.cs using:

    services.AddDbContext<Db2Context>(options =>
    {
        options.UseDb2(connection, si =>
        {
            si.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_02));
        }
    });
    

And that's all I've done. Model the entities and use LINQ as well.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I'm trying to figure out where to get those license files so I can try this. I see lots of potential license files listed here and here, but none of them matches your filenames exactly. Maybe the filenames vary based on the version of DB2 you have?
Here's a description how to get the license: stackoverflow.com/a/63612855/414803

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.