Index (zero based) must be greater than or equal to zero and less than the size of the argument list IBM .net core

1

I am tying to use IBM DB .NET Provider for MS .NET Core and no matter what I do with creating my context every time I try to use it I get the following error.

"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."

Context Class

    public class IBMContext : DbContext
    {

        public IBMContext()
            : base()
        {
        }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {

        optionsBuilder.UseDb2(@"Server=server;Database=DB;userid=user;password=pass",
            p => p.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_01));

    }

    public virtual DbSet<Table> Table{ get; set; }

}

Model.cs

[Table("Table")]
public class Table
{
    [Key]
    public int Key{ get; set; }

    public string Stat{ get; set; }

    public string Jul{ get; set; }

    public string App { get; set; }

    public string Date { get; set; }

}

Use

     static void Main(string[] args)
    {
        Console.WriteLine("Test");

        var context = new IBMContext();

        var result = context.Table.ToList();

        Console.ReadLine();
    }

Package

IBM.EnityFrameworkCore(1.1.1.101)

Full Error Stack

System.FormatException occurred HResult=0x80131537 Message=Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Source= StackTrace: at IBM.Data.DB2.Core.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn) at IBM.Data.DB2.Core.DB2Connection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open() at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer) at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__31.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__152.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext() at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at IBMEntityFrameworkCoreTest.Program.Main(String[] args) in C:\CodeBase\IBMEntityFrameworkCoreTest\IBMEntityFrameworkCoreTest\Program.cs:line 24

entity-framework
asp.net-core
db2
asked on Stack Overflow Aug 29, 2017 by Derek Hackett • edited Aug 29, 2017 by Derek Hackett

1 Answer

2

I have found out that this is caused by have another version of driver from IBM entered in my environment variable Path. You can test what Visual Studio is looking at by running a Visual Studio Command Prompt and typing

db2level

I had

C:\PROGRA~1\IBM\IBMDAT~1\BIN

You need to remove this and make sure you have

C:\Users\<user_name>\.nuget\packages\IBM.Data.DB2.Core\1.1.1.101\build\clidriver" 

The command you need to run to update the path variable

Set PATH=%PATH%;(your new path);

You can find out more information about this at

https://www.ibm.com/developerworks/community/forums/html/topic?id=9a107d00-d814-440c-b438-faa4d020ae1a&ps=25

answered on Stack Overflow Aug 29, 2017 by Derek Hackett

User contributions licensed under CC BY-SA 3.0