3

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:

<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" />
</providers>

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?

3
  • Inspecting the IBM.Data.DB2 and IBM.Data.DB2.EntityFramework dlls the method IBM.Data.DB2.DB2Trace.Entity_CheckDB2Trace() is marked internal and is being called from another namespace
    – dpix
    Jan 6, 2015 at 21:24
  • Are you able to perform code first? I'm ran into errors while trying to execute code-first EF6 model.
    – Roy Lee
    Jan 21, 2015 at 11:48
  • 1
    Haven't tried code first. Once I got this driver installed properly I found a bunch of issues though as we are running an older version of DB2 to the matching driver and it appears they aren't compatible. We've decided to stick with EF5 for the time being.
    – dpix
    Jan 23, 2015 at 0:58

2 Answers 2

3

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

2
  • Hi @dpix, i'm in to the same problem, but in the preliminary stage. I have got visual studio 2015 + entity framework 6 + IBM.Data.DB2.EntityFramework, Version=10.5.5.6 installed. when i open ODBC connection manager i can find IBM DB2 ODBC Driver Version 10.05.00 referring to DB2CIL.dll. My problem is im unable to get DB2 data source in Entity Data Model Wizard. Am i missing anything?? Please can you help? Thank you
    – Ramu
    Apr 18, 2016 at 15:10
  • Hmm sorry @Ramu, It's been a while since I've touched anything DB2. I never got any integration going with Visual Studio. Good luck! P.S. once we actually got this working the db2 drivers were very buggy, I think we ended up using a 3rd party driver instead
    – dpix
    May 11, 2016 at 5:39
0

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.