Thread: Database connection problem

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    10

    Database connection problem

    when i am trying to debug my project. I am getting error while trying to establish a database connection. My connection is failing.
    I am using Rogwave Library to connect to database.
    I am using oracle database.

    The Following is my code
    Code:
    	RWDBDatabase	oDBWork = RWDBManager::database (	sDBAccessLib,
                                           	sDBName, sDBUser, sDBPassWd, sDBServerName );
    
    	oDBWork.defaultConnections(3);// dbTools verwaltet 3 Connection
    
    	// Get and test a DB connecetion
    	RWDBConnection oConn1	=	oDBWork.connection();
    	RWDBConnection oConn2	=	oDBWork.connection();
    	RWDBConnection oConn3	=	oDBWork.connection();
    
    	
    	if ( (!oDBWork.isValid()) || (!oConn1.isValid()) || (!oConn2.isValid()) || (!oConn3.isValid()) )
    	{
    		oSAPAuftragLog->WriteLogFile ("Can't connect to data base <"  + sDBName + ">");
    		cout	<< ProgTitel << ": Can't connect to data base " << sDBName << endl;
    		EndProg (FALSE);
    		return 1;
    	}
    The below are my runtime values:
    Code:
    -	sDBAccessLib	{...}
    -	data_	{???}
    	std::allocator<char>	{...}
    +	_C_data	0x00bb3dec "or84315d.dll"
    
    -	sDBName	{...}
    -	data_	{???}
    	std::allocator<char>	{...}
    +	_C_data	0x00bb333c "AVVT"
    
    -	sDBUser	{...}
    -	data_	{???}
    	std::allocator<char>	{...}
    +	_C_data	0x00bb34bc "Master"
    
    -	sDBPassWd	{...}
    -	data_	{???}
    	std::allocator<char>	{...}
    +	_C_data	0x00bb33fc "Test"
    
    -	sDBServerName	{...}
    -	data_	{???}
    	std::allocator<char>	{...}
    +	_C_data	0x100b2f54 ""
    If i try to connect toad to oracle database. I am able to connect it.

    Code:
    Database: AVVT
    
    User / Schema: Master
    
    Password: Test
    
    Connect as : Normal
    
    Connect Using: OraHome81 (Oracle Root)
    The below is the error i am getting in my log. while trying to connect through my program
    Code:
    15.07.2011 20:27:33 [SERVERERROR] ORA-12154: TNS:could not resolve the connect identifier specified
    
    Error number : 12154
    Server: 
    
    15.07.2011 20:28:07 Can't connect to data base <AVVT>
    In case to modify the TNS File. Please expalin in details.
    Which location i will find the TNS File ?.
    what to modify in TNS FIle ?.
    How Toad is able to connect to database ?.
    In toad there is a button called TNSNames Editor.
    If i click that i am able to find the below entries.
    Code:
    File Name : C:\Oracle\Ora81\Network\Admin\tnsnames.ora
    AVVP = 
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.135.41.49)(PORT = 6210))
        )
        (CONNECT_DATA =
          (SID = AVVP)
        )
      )
    AVVT = 
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.135.43.21)(PORT = 6210))
        )
        (CONNECT_DATA =
          (SID = AVVT)
        )
      )
    AVV2P = 
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.150.128.45)(PORT = 1565))
        )
        (CONNECT_DATA =
          (SID = AVVP)
        )
      )
    Please help me to find out why my program is not connecting to oracle database.

  2. #2
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    Help me . to solve the above problem

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Some points:
    1. Code:
      if ( (!oDBWork.isValid()) || (!oConn1.isValid()) || (!oConn2.isValid()) || (!oConn3.isValid()) )
      If you want to know which of these is failing, well, that's too bad because you'll never know. Why not test each one as they happen?
    2. Despite what you have apparently been told, errno and perror/strerror are not the work of the devil. You may want to use them.
    3. Code:
      -	sDBServerName	{...}
      -	data_	{???}
      	std::allocator<char>	{...}
      +	_C_data	0x100b2f54 ""
      Is this data that has been edited for our safety, or are you really trying to connect to a blank server?

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    I have tried by giving DBServerName. Even though it is failing.
    But I am not able to understand why it is throwing tnsnames.ora error.
    The error i am getting in my log is as follows.
    But that entry is there. If i open in toad it is opening.
    Code:
    18.07.2011 11:46:28 SAPAuftrag: -d AVVT 
    18.07.2011 11:46:28 SAPAuftrag: Version V1.2.3.2 Datum 01.10.2009
    18.07.2011 11:46:39 [SERVERERROR] ORA-12154: TNS:could not resolve the connect identifier specified
    
    Error number : 12154
    Server: 
    
    18.07.2011 11:46:46 Can't connect to data base <AVVT>
    18.07.2011 11:46:47 ***********************************************************
    18.07.2011 11:46:47 SAPAuftrag: Ende mit Fehlern

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    What happens if you try to connect to the other databases in the TNS file?

    Is it a drive/server permissions fault, where the account your app is running in has less priveliges than TOAD? (make sure your TOAD session is usig the same account as your app)

    Can you TSNPing your database?

    Is it a network premissions thing where TOAD is allowed to access the PORT but your app is not?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    if i try to connect to the other databases in the TNS file. I am getting the same error.
    15.07.2011 20:27:33 [SERVERERROR] ORA-12154: TNS:could not resolve the connect identifier specified

    Error number : 12154
    Server:
    If am trying to connect the database from my collegue system with my login credentials. It is connecting Successfully. Only from my system i am not able to connect to database.

    If i do TSNPing to database.
    C:\>tnsping AVVT 3

    TNS Ping Utility for 32-bit Windows: Version 8.1.6.0.0 - Production on 18-JUL-20
    11 19:34:21

    (c) Copyright 1997 Oracle Corporation. All rights reserved.

    Attempting to contact (ADDRESS=(PROTOCOL=TCP)(HOST=10.135.43.21)(PORT=62 10))
    OK (520 msec)
    OK (680 msec)
    OK (680 msec)
    Tell me how to check for a network premissions thing where TOAD is allowed to access the PORT but your app is not. ?

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    SQL*Net FAQ - Oracle FAQ

    FYI: I have never used "Oracle SQL*Net". Just Google for info.

    Tim S.
    Last edited by stahta01; 07-18-2011 at 08:43 AM.

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    I was not able to find it by google the problem.
    The solution given are cross verified. and same. TNS_ADMIN reg entries are there in my registry and it is pointing to tnsnames.ora directory. and entries are there in tnsnames.ora file.

    plz help me to find out actuall problem.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by kandas.soft View Post
    If am trying to connect the database from my collegue system with my login credentials. It is connecting Successfully. Only from my system i am not able to connect to database.
    So your app can connect to the DB from another PC but not from your PC?

    Copy his TSNNames.ora file. Compare it to yours with a utility like BeyondCompare (has free trial) and ensure they are EXACTLY the same.

    If they are then get your IT Operations to check your PC/account has the same permissions / priveliges as your collegue's PC/account.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    It was not because of access rights. I had admin rights in my system.
    Finally the problem is solved.

    Actually in my system there were 2 installations one was oracle 8 and other was oracle 10g. Since my program needs only oracle 8. I uninstalled oracle 10g.
    Now my program is able to connect with database.

    Many thanks to all of u.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create connection to database in C
    By gmalachi in forum C Programming
    Replies: 2
    Last Post: 12-29-2010, 05:33 AM
  2. Connection problem
    By Tommo in forum Tech Board
    Replies: 9
    Last Post: 10-03-2007, 12:45 PM
  3. Database connection...
    By MipZhaP in forum Windows Programming
    Replies: 3
    Last Post: 09-11-2004, 08:36 AM
  4. oracle database connection
    By blue8173 in forum C Programming
    Replies: 1
    Last Post: 03-16-2004, 04:30 PM
  5. connection to database through c++
    By teja22 in forum C++ Programming
    Replies: 1
    Last Post: 10-15-2001, 04:10 AM