Monday, January 30, 2012

Entity Framework and IBM DB2 Database

Recently I was doing one POC on Entity Framework and IBM DB2 database. Here is how we can make entity framework to consume IBM DB2 database.


IBM DB2 runs mostly on zOS or Linux platform. They do also have express edition which runs on Windows OS. I used the IBM DB2 Express edition which is a free downloadable from IBM site. Also, you will need the IBM DB2 connector VS Add-In to be able to establish connection with DB2 database. Don't worry, here is the link to download both these components


https://www14.software.ibm.com/webapp/iwm/web/download.do?source=swg-db2expressc&S_PKG=dlwin32&S_TACT=100KG25W&lang=en_US&dlmethod=http


Once you install and setup the IBM DB2 Express edtion and  VS Add-In just follow the below steps to establish connectivity from EF to DB2 database.


1) Create a sample project in VS2010
2) Add new ADO.NET Entity Data Model to the project












3) Click Next and select "New Connection"
4) In the connection dialog, click the "Change Datasource" button



















5) In the Data Sources screen, select "IBM DB2 and IDS servers"

















6) Select the "Server", enter "Username", "Password", "Database" and do a Test Connection to database. If DB connection is successful, goto next step.




















7) Select the options shown in the screenshot below and click "Next"



















8) Select the Tables, Views you need in this step as shown in the screenshot



















9) Voila, you should be able to see all the tables, views selected in the previous steps in the Model file














10) Now you should be able to consume the DB normally using EF.

Ok, now that you have done with the implementation; How do we redistribute the App to TEST or PROD server? Answer is yes, it is possible. You will need any one of the below drivers to achieve DB2 connectivity from TEST or PROD servers;

1) IBM Data Server Client: most complete, includes GUI Tools, drivers



2) IBM Data Server Runtime Client: a lightweight client with basic functionality, and includes drivers


3) DB2 Runtime Client Merge Modules for Windows: mainly used to embed a DB2 runtime client as part of a Windows application installation


4) IBM Data Server Driver for JDBC and SQLJ: allows Java applications to connect to DB2 servers without having to install a full client


5) IBM Data Server Driver for ODBC and CLI: allows ODBC and CLI applications to connect to a DB2 server without the large footprint of having to install a client


6) IBM Data Server Driver Package: Includes a Windows-specific driver with support for .NET environments in addition to ODBC, CLI and open source. This driver was previously known as the IBM Data Server Driver for ODBC, CLI and .NET


And of course, there are some limitations with this approach. Please read through the limitations As-Is provided by IBM before going forward with this approach.
 
http://www.ibm.com/developerworks/wikis/display/DB2/IBM%20Data%20Server%20LINQ%20Entity%20Framework%20Limitations