Ana Franco
Ana Franco

Reputation: 1821

Entity framework provider error with IBM DB2 I Series database

Ok here's my problem I want to use entity framework with a DB2 for I series database, in a database first way, but it has been really complicated to get a successful connection.

First I was trying to create an Entity Data model using the "IBM DB2 and IDS Servers" Data source but although I created a successful connection to a LUW DB2 I haven't been able to do it with the DB2 for I series, I have tried ports 446 it said there was a licence problem, 9471 generated a connection error, 8471 kept waiting and 50000 with no success, I even tried using no port, but it didn't work.

Data source selection

Connection properties

So I choosed to use the IBM DB2 for i data source, this option allows me to connect but when I try to use Entity Framework 6.1.3 I get an error telling me that EF 6.x is not compatible with this version.

Data source for i series

enter image description here

So, I downgraded EF to version 5.0 to try to create the Entity Model any way and then upgrade the EF version, but, when I click on next after selecting EF 5.0 the Entity Data Model Wizard disappears before showing the database objects and settings and the model doesn't get created.

Then I decided I didn't need an edmx file I could do the mapping manually now that the connection is working so I started creating the classes to do the mapping:

AppContext:

public class AppContext: DbContext
{
    public AppContext() : base( "connectionString" )
    {
    }

    public DbSet<Data> Datas { get; set; }
}

Data: [Table("data")] public class Data { [Column("id")] public int Id { get; set; }

    [Column("name")]
    public string Name { get; set; }
}    

And finally the test:

public class Program
{
    static void Main(string[] args)
    {

        using (var ctx = new AppContext())
        {
            Data data = new Data() { Id = 1, Name = "A Name" };

            ctx.Datas.Add(data);
            ctx.SaveChanges();                
        }
    }
}

I installed the EntityFramework.IBM.DB2 nuget version 6.0.7 and changed my Web.config to add the connection string, I found there a new provider named "IBM.Data.DB2" and tested the connection but I began having the same problems I had with the first connection, with the different ports.

So I thought that this provider must be the one for the first connection and I needed the one for I series son I changed provider to "IBM.Data.DB2.iSeries" and tried again changing some parameters in the connection string but now I'm getting this error:

The 'Instance' member of the Entity Framework provider type 'IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Here are my connection strings and providers from my Web.config:

<connectionStrings>
    <add name="DB2Connection" providerName="IBM.Data.DB2" connectionString="DataSource=192.168.1.54;UserID=XXXX;DefaultCollection=XXXX;Database=DB10000010; Password=XXXXXX;" />
    <add name="connectionString" providerName="IBM.Data.DB2.iSeries" connectionString="Server=192.168.1.54;UserID=XXXXX;Database=DB100000010; Password=XXXXX;" />
</connectionStrings>

<providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    <provider invariantName="IBM.Data.DB2" type="IBM.Data.DB2.EntityFramework.DB2ProviderServices, IBM.Data.DB2.EntityFramework, Version=10.5.5.6, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />
    <provider invariantName="IBM.Data.DB2.iSeries" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26" />
</providers>

I also found a new IBM I Access that is supposed to replace the old IBM DB2 i series for windows provider, but couldn't find a data source that works with it

IBM I Access app

Ok so I'm running out of ideas, Can anyone help me to use entity framework with IBM DB2 for i series?

Thanks

Upvotes: 0

Views: 3092

Answers (1)

Oscar Llop
Oscar Llop

Reputation: 201

To connect with DB2 iSeries you must connect using port 446. There is a licesing issue. You must contact IBM to obtain your license:

ADM12008C The product "IBM Data Server Driver Package" does not have a valid license key installed and the evaluation period has expired. Functions specific to this product are not enabled. If you have licensed this product, ensure the license key is properly installed. You can install the license using the db2licm command. The license file can be obtained from your licensed product CD.

Follow this link for more information:

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

Upvotes: 0

Related Questions