I had a heck of a time trying to find information on this topic. I would like to save the next person down the line some hassle, so I am going to show you how to setup a simple configuration for Entity Framework Code First and Visual Studio.
Note* This is primarily for people who do read level applications. I have not tried this with inserts as I have no need for inserts or updates so this has been untested in that scenario.
First install visual studio add-ins for whatever version of DB2 you will be connecting to. This will not install anything to visual studio if you are using < 10.0 but it will install the libraries you need.
We are primarily interested in 2 libraries:
public class DB2Context : DbContext
public DB2Context() : base("name=DB2Entities")
protected override void OnModelCreating(DbModelBuilder modelBuilder)
public IEnumerable<MyModel> MyModels()
var Query =
Then for your application settings or web settings connection string
<add name="DB2Entities" connectionString="database=MyDatabase;user id=username;password=password;server=myserver:446" providerName="IBM.Data.DB2" />
BOOM! You just connected yourself to db2.
Have an awesome day