locked
How to connect DB2 Database from C#.net RRS feed

  • Question

  • Hi,

    I need to read data set from IBM DB2 in my c#.net application.

    Please provide help.


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS

    Monday, March 12, 2012 7:26 AM

Answers

All replies

  • The first thing is you need to construct a proper connection string which looks like below,

    Server=myAddress:myPortNumber;Database=myDataBase;UID=myUsername;PWD=myPassword;

    Then, it is common ADO.NET programming where you create a command object passing the query, create dataset, create adapter and execute command to read data into table and so on.

    For more info on DB2 connection string visit below page,

    http://www.connectionstrings.com/ibm-db2

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Kris444 Monday, March 12, 2012 8:49 AM
    • Unproposed as answer by Hasan Jamal Siddiqui Tuesday, March 13, 2012 11:53 AM
    Monday, March 12, 2012 7:36 AM
  • Hi Adavesh,

    Thx for solution.

    can you provide me link where i can download IBM.Data.DB2 dll


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS

    Monday, March 12, 2012 8:09 AM
  • IBM DB2 ADO.NET provider is not free. But you can download trial version at below locations.

    http://www.datadirect.com/product-downloads/connect-ado-net.html

    https://www14.software.ibm.com/webapp/iwm/web/reg/download.do?source=swg-dm-db297trial&S_PKG=dl&S_TACT=109HF12W&lang=en_US&cp=UTF-8

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, March 12, 2012 8:59 AM
  • Hi Adavesh.

    Here client is ussing licensed DB2.

    can i ask to client for provide me ddl.

    can u provide me ddl name so i can ask to client for dll.


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS

    Monday, March 12, 2012 9:11 AM
  • I don't think it is just one dll. To get the complete provider, it is better to install the provider which might consist of several dll. So, you can ask for the provider setup itself.

    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, March 12, 2012 11:54 AM
  • Hi Avdesh

    I have instal IBM DB2 Client Software.

    can u guide me what i do for next step.


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS

    Monday, March 12, 2012 12:40 PM
  • To be frank, I have never worked on DB2 + .NET. So, I am not sure about the how the connection string should be constructed. You can follow my first post in this thread to create the connection string. Then, you can create connection object and do normal ADO.NEt operations.

    If you are still facing the problems, you can ask the question in DB2 ADO.NET (click below link) Forums where you might get better support.

    http://www.ibm.com/developerworks/forums/forum.jspa?forumID=467


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, March 12, 2012 2:27 PM
  • Hi ,

    I have IBM DB2 Client on my system and also i found using IBM.Data.DB2;

    and usse this code to connect from data base

    String myConnectionString = "Server=*...*;Database=CG****;UID=****ja;PWD=******";

    DB2Connection myConnection = new DB2Connection();
    myConnection.ConnectionString = myConnectionString;
    myConnection.Open();
    //execute queries, etc
    myConnection.Close();

    but when try to connect the error will show as like

    ERROR 08001 IBM SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "10.10.**.*". Communication function detecting the error: "connect". Protocol specific error code(s): "10061", "", "*". SQLSTATE=08001

    Please ptovide me solution


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS

    Monday, March 19, 2012 11:11 AM
  • Hi Hasan,

    did you check below article about db2 with c#

    http://www.codeproject.com/Articles/26344/Connection-to-DB2-from-NET

    Regards

    Sneha

    Monday, March 19, 2012 11:31 AM
  • Thx Sneha,

    i was got the solution . i was miss the port number.

    and also that link have provide me more breafe.


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS

    Tuesday, March 20, 2012 5:51 AM
  • Hi Hassan kindly check this link here is fetching data from sql and displaying in MessageBox in C#.http://codingresolved.com/discussion/40/how-to-connect-database-in-c#Item_3
    • Proposed as answer by Waqas Silat Thursday, August 9, 2012 8:32 PM
    Sunday, August 5, 2012 8:22 PM
  • Thx for link.

    it has been resolved already.


    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Share Point Application Developer,TCS

    Thursday, August 16, 2012 11:10 AM
  • Actually the "Server" directive does not work for OleDB drivers. It is used when specifying ADO-Remote access which not all client drivers support. Db2 is one of them.

    In such case, meaning, if you want to use OleDb instead of ADO.net, and if you are in need to connect to databases located in a remote server, then, you can either: 1) catalog the remote databases and specify the cataloged name as a hostname or, better yet, 2) use the following connection string which works really well:


    "Provider={0}; Database={1}; HostName={2}; Protocol=TCPIP; Port={3}; CurrentSchema={4}; UID={5}; PWD={6}"

    where:

    {0} is the name of the desired driver. ex: IBMDADB2
    {1} is the name of the database to connect
    {2} is the name of the remote/local SERVER where the database resides. Use localhost for local
    {3} usually 50000
    {4} the name of the schema where tables reside in the database
    {5} user id to connect to database
    {6} password for user id

    Monday, August 8, 2016 8:49 PM
  • Thursday, July 5, 2018 10:18 AM