EntityFramework.IBM.DB2 can't connect to db2

db2 entity-framework entity-framework-6


I'm trying to connect to a db2 instance using EF6 and the new IBM Entity Framework data provider found here

have added the provider to the app config:

    <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=, Culture=neutral, PublicKeyToken=7c307b91aa13d208" />

and connection string looks like so:

<add name="DB2" connectionString="Server=blah;Database=meh;Uid=user;Pwd=pword;" providerName="IBM.Data.DB2" />

I can instantiate a context but when I try to run a query it throws a MethodAccessException:

Attempt by method 'IBM.Data.DB2.EntityFramework.DB2ProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)' to access method 'IBM.Data.DB2.DB2Trace.Entity_CheckDB2Trace()' failed.

I have installed the DB2 Version 10.5 Fix Pack 5

Any ideas as to what I might be doing wrong?

1/6/2015 9:07:35 PM

Accepted Answer

Turns out I had installed the 10.5.5 driver but it failed to be set as the default. After running the "Default DB2 and Database Client Interface Selection wizard" (found just by searching in the start menu) and setting the new one as the default it worked fine

1/7/2015 12:29:03 AM

Popular Answer

@Ramu, I have recently started migrating one of our legacy applications and started figuring out how to connect to IBM DB2 using Entity Framework 6. To answer straight to your question - its not possible to work in VS 2015 as IBM database add-ins are supported only until VS 2013. We have contacted IBM and they have no idea if they are going to release these add-ins for VS 2015.

As a work around I built my repository in VS 2013 and made it as a nuget package. I have imported that package into my VS 2015 project. Now packages are much cleaner way of doing it than giving hard dll references.

This is how I setup the environment

  1. Install IBM DB2 10.5 with Fix-pack 7. That should get IBM Data server Client 10.5.
  2. On the same installation package – Install IBM Database Add-Ins for Visual Studio.
  3. Install IBM Data server Driver 10.5.
  4. Install EF Tools for VS2012/VS2013

Go to programs and features - and always make sure both IBM Data server client and IBM Database add-ins for VS should have same version, release and fix-pack level.

Hope this helps.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow