Search code examples
entity-framework-coredb2db2-400

Why does DB2 put my UserId from the connection string as my table name?


I'm trying to us Entity Framework Core to query my DB2 database. Here's how I register it:

services.AddDbContext<DB2Contexte>(options =>
                options.UseDb2(Configuration.GetConnectionString("DB2"),
                    builder =>
                    {
                        builder.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_01);
                        builder.UseRowNumberForPaging();
                        builder.MaxBatchSize(1);
                    }));

That's the class the is use as a DbSet:

enter image description here

And there's my connection string:

Server=something;UserID=U_SERVTI;Password=something;Database=something; LibraryList=something;CurrentFunctionPath=*LIBL

Than when I try to query the database using simple LINQ:

_dbContext.PersonneRessource.FirstOrDefault()

I get this error:

ERROR [42704] [IBM][AS] SQL0204N "U_SERVTI.DX37PERE" is an undefined name.

Why is the UserId in the name? Shouldn't it just query the table and leave out the UserID?

I use IBM.EntityFrameworkCore-lnx version 3.1.0.500.


Solution

  • Db2 for IBM i, for historical reasons, supports two naming conventions; SYS and SQL.

    By default, external connections will use SQL naming and like the rest of the Db2 family, unqualified table references will be implicitly qualified with the "run-time authorization identifier"; normally the user id used to connect.

    With SYS naming, unqualified table references are qualified with *LIBL and the library list is used to find the table.

    On your connection string, you're going to want to add Naming=SYS (or maybe Naming=*SYS )

    Note that SYS vs. SQL naming affects just about every unqualified reference. Be sure to look at the documentation.