How to fetch data from IBM DB2 database RRS feed

  • Question

  • Hi,


    I am using C# 2.0 for developing windows based application.  Currently we are using IBM DB2 as our database.  How I will connect to DB2 database and fetch the data. 

    From where I will download IBM.Data.DB2.dll.



    Selvakumar R


    Monday, March 31, 2008 2:01 PM


All replies

  • You have two free options use Microsoft OLE DB provider for DB2 or use IBM native ADO.NET provider, the OLE DB provider is one of many add on to SQL Server you can download in the first link and there is IBM created native provider in the second link.




    Monday, March 31, 2008 5:16 PM
  • Hi,

    Thanks for giving solution.  I used second method to get data from DB2, IBM.Data.DB2.dll.  I given connection string, command text everything, But it shows some exception. 

    I didn't install DB2 Client in my machine, I got IBM.Data.DB2.dll from my server machine.  I refered this dll into my application.  I am attaching my code snippet here..


    DB2Connection Con = new DB2Connection("Server=myserver; Database=dbname; UID=Db2admin; PWD=password;");

    DB2Command cmd = new DB2Command();

    cmd.CommandText = "Select * from Reports";

    cmd.Connection = Con;

    cmd.CommandTimeout = 60;


    DB2DataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);


    Exception is raising in connection string.  Please tell me why this exception is raising, whether i need to install client DB2 in my machine or reference to dll is sufficient to get the data from db.

    Followig is the Exception message.

    System.TypeInitializationException: The type initializer for 'IBM.Data.DB2.DB2Connection' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'db2app.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

       at IBM.Data.DB2.v.nmpTraceOn()

       at IBM.Data.DB2.v.e()

       at IBM.Data.DB2.DB2ConnPool.d()

       at IBM.Data.DB2.DB2ConnPool..ctor()

       at IBM.Data.DB2.DB2Connection..cctor()

       --- End of inner exception stack trace ---

       at IBM.Data.DB2.DB2Connection..ctor(String connectionString)

       at TestWebServiceConnection.Form1.ApplicationFormIndexReport() in D:\Selvakumar\VS Application\TestWebServiceConnection\TestWebServiceConnection\Form1.cs:line 396





    Selvakumar R


    Tuesday, April 1, 2008 8:52 AM
  • IBM says you need to install the programmer's tool kit which includes the client software.



    Tuesday, April 1, 2008 5:44 PM
  • HI,


    Thanks a lot for ur immediate response.


    I installed DB2 client in my local system.

    Could you please tell me the exact path from were i can get the Tool Kit Installer?


    If I want use OLEDB, whether i need to install Sql Server in my machine.  Because DB2 provider is not avilable in the OLEDB, so i need to install DB2OLEDB.exe.  It requires sql server 2005 in local machine.




    Wednesday, April 2, 2008 6:17 AM
  • No you don't need SQL Server it was just provided by SQL Server for ETL(extraction transformation and loading) task with DB2.  I have found the IBM native .NET provider will cost you money because it is part of their client access tool.  So here is a tutorial to use OLE DB and IBM own ADO.NET tutorial with VS2005 add in.   There is a link to IBM .NET forums on the right side of the last link if you are still having problems.






    Wednesday, April 2, 2008 7:35 PM
  • Thanks for your suggestion.  I downloaded .Net DB2 provider from IBM site.  It is working fine. 

    Sunday, April 6, 2008 8:56 AM
  • Selvakumar:


    I was wondering if you can also help me out.  I have the same situation.  I have developed a user control using and displaying it in a web page.  After you installed the toolkit, did you have to install it on the machines where the application will be deployed or not?


    I installed the toolkit on my machine, everything is fine, but on the users machine I get IBM.Data.DB2 provider not found or if I use the generic ADO.NET code to connect to the database using the Factory class, I get .NET Framework provider not found for IBM.Data.DB2.


    If you can help me that will be great.






    Friday, May 2, 2008 3:38 AM