Search code examples
c#db2entity-framework-6edmx

Generating an EDMX from a DB2 Database


I'm trying to create an EDMX file using VS2013 so I can read/write from a DB2 Database. I go through the same process as creating the EDMX from my SQL tables (Right click on project -> Add New Item -> ADO.NET Entity Data Model -> EF Designer from database -> Not using SQL this time so: new connection -> Change data source) but in the Data Source option, DB2 is not available. I have 2 SQL options and that's it.

Data Source

So after doing some investigating around here along with some other places, it looks like EF wasn't actually setup to do this until a plugin for EF6 came out. So using Nuget I have installed EntityFramework.IBM.DB2 version 6.0.3 hoping that would add something to my Data Source area allowing me to choose a DB2 database but still nothing.

I'm gonna try to give as much info about my system here as I know so if I ramble...which I tend to do...sorry in advance.

I'm on Windows 7 using VS2013 Pro edition. I have an ODBC connection setup and it's been working great for years. I can go into the ODBC Manager and test my connection to both Test and Production DB2 and it connects just fine.

The ODBC Data Source Administrator is version 6.1.7601.17632 and I'm using the IBM DB2 ODBC Driver...looks like it's version 10.5.500 (although I'm not 100% sure if I'm looking in the right place to get that version number)

I can also go into Access and connect to the DB2 databases using the ODBC connection and bring back the tables and their data.

I can also write SQL statements directly into my code with the connection string setup (that I assume uses that same ODBC connection) and reads data from SQL and calls Stored Procedures connected to those DB2 tables to write/update/delete.

Lastly, it seems like a previous coworker was able to make this work. I have loaded his code and when I pull up the EDMX, I get the nice graphical display of all the tables. But when I try to click Update from Database, I get an error:

Error Message

Sadly, he is no longer with the company and his computer is not in a condition where I can take a look at it.

So it feels like this is something that can be done and that my computer is almost setup to do this...with the exception of something I'm missing that will allow me to add that DB2 type data source to that first image above so I can select it, put the credentials in and move on.

Any help will be truly appreciated...


Solution

  • In order to use Entity Framework and Visual Studio... you need to install IBM's drivers as well as a Visual Studio Add-in (to make DB2 show up in the dropdown of data providers and create an EDMX properly). The following is the setup we use to communicate with DB2 z/os. I am not sure whether or not these same drivers work with DB2 Linux/Unix/Windows.

    http://www-01.ibm.com/support/docview.wss?uid=swg24041453

    The above link is for the client version 10.5 fix pack 7. I have used this to setup both Visual Studio 2013 and Visual Studio 2015 in Windows 7/8.1 (have not tested on a Windows 10 development machine).

    Here's what you will need to download and install

    1. Data server driver package (Windows)
    2. Database Add-ins for Visual Studio

    You will also need a license file (your DBA should be able to provide this for you, or at least download one using their IBM login)

    Install the data server drivers first, then the add-ins. Copy your license file to C:\Program Files\IBM\IBM DATA SERVER DRIVER\license

    You will still need the EntityFramework.IBM.DB2 nuget package if you wish to use EF6, as the Visual Studio Add-ins by themselves are only compatible with EF5