Error connecting to DB2 Databse from C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhavanims
    New Member
    • Nov 2014
    • 5

    Error connecting to DB2 Databse from C#

    while opening a new DB2 connection using ODBC connection i get the
    following error message

    ERROR [08004] [IBM][CLI Driver] SQL30061N The database alias or
    database name \"DATABASENA ME \" was not found at the
    remote node. SQLSTATE=08004\ r\n\r\nERROR [IM006] [Microsoft][ODBC
    Driver Manager] Driver's SQLSetConnectAt tr failed"string

    here i find some additional spaces are appended along with the
    DATABASENAME and hence my connection fails.how to make a successful
    connection here?

    server is DB2 UDB for OS/390 7.1.1
    client is DB2 CONNECT PE DB2 v8.2 installed in windows XP

    I used IBM DB2 Data Access Application Blocks for .NET which uses .NET
    native provider for DB2...still i get the same error message!

    i use IBMDADB2 Provider
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I have not used an IBM DB2 database before; however, that error messages states that the database that you are expecting to connect to does not exist.

    Use the IBM tools available to you to ensure that your database server actually contains the database.

    If it does not contain the database then you will have to run the appropriate SQL scripts/statements in order to create the database that you are expecting to be there (with the name that you are expecting it to have)

    -Frinny

    Comment

    • bhavanims
      New Member
      • Nov 2014
      • 5

      #3
      Frinny

      Thank you for your response. I am able to connect to the DB and run SQL from IBM tool (DB2 Connect). I am having trouble connecting to the DB from C#.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Could you post your connection string?

        Maybe there's something wrong with it that you missed.

        Double check that the database names match, the server locations match etc....

        -Frinny

        Comment

        • bhavanims
          New Member
          • Nov 2014
          • 5

          #5
          "Provider=IBMDA DB2; Database=****; HOSTNAME=****; PROTOCOL=TCPIP; PORT=123; uid=****; pwd=****;"

          this is how my connection string looks.

          I did installed IBMDADB2 driver.

          Comment

          • bhavanims
            New Member
            • Nov 2014
            • 5

            #6
            Code:
            string db2ConStr = "Provider=IBMDADB2; Database=****; HOSTNAME=****; PROTOCOL=TCPIP; PORT=123; uid=****; pwd=****;"
            
                public DataSet GetCPData()
                {
                    OleDbConnection db2Con = null;
                    OleDbDataReader CPReader = null;
                    try
                    {
                        db2Con = new OleDbConnection(db2ConStr);
                        string CPSelect = "SELECT Query;";
            
                        OleDbCommand CPCommand = new OleDbCommand(CPSelect, db2Con);
                        db2Con.Open();
            It fails on db2Con.Open();

            I get

            SQL30061N The database alias or database name "**** " was not found at the remote node. SQLSTATE=08004
            Last edited by Frinavale; Nov 12 '14, 07:26 PM.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Ok,

              According to the IBM DB2 Connection String Documentation your connection string should look like:

              Code:
              string conString = "Server=serverAddress:serverPortNumber;Database=theDataBase;UID=myUsername;PWD=myPassword;";

              Your connection string does not match that.

              Your connection string looks to be missing the address (the server's IP address or computer name for the if it is on an internal network with domain name resolution)


              -Frinny
              Last edited by Frinavale; Nov 12 '14, 07:31 PM.

              Comment

              • bhavanims
                New Member
                • Nov 2014
                • 5

                #8
                No, It expects Provider in the connection string.

                "Provider=IBMDA DB2; Database=****; HOSTNAME=****; PROTOCOL=TCPIP; PORT=123; uid=****; pwd=****;"

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  Well, if your connection string doesn't work, and the documentation I found is not correct, consider trying to use the MsDb2Connection StringBuilder Class (<- a link to the documentation on the topic)

                  -Frinny

                  Comment

                  Working...