Using tnsnames.ora

Where can I ask a questio about OCI?
I want to make a connection using tnsname.ora except using a dblink and username and password whit oci. I used this code up to know :
OCIInitialize((ub4)mode, (dvoid *)0,
(dvoid*(*)(dvoid *ctxp, size_t size))0,
(dvoid*(*)(dvoid ctxp, dvoid memptr, size_t newsize))0,
(dvoid (*)(dvoid ctxp, dvoid memptr))0);
OCIEnvInit(&envhp, (ub4)OCI_DEFAULT, (size_t)0, (void**)0);
OCIHandleAlloc((dvoid*)envhp, (dvoid**)&errhp, (ub4)OCI_HTYPE_ERROR,
(size_t)0, (dvoid**)0),"");
OCIHandleAlloc((dvoid*)envhp, (dvoid**)&srvhp, (ub4)OCI_HTYPE_SERVER,
(size_t)0, (dvoid**)0);
OCIServerAttach(srvhp, errhp, (text*)dblink, (sb4)strlen(dblink), (ub4)OCI_DEFAULT);
OCIHandleAlloc((dvoid*)envhp, (dvoid**)&svchp, (ub4)OCI_HTYPE_SVCCTX,
(size_t)0, (dvoid**)0);
OCIAttrSet((dvoid*)svchp, (ub4)OCI_HTYPE_SVCCTX, (dvoid*)srvhp, (ub4)0,
(ub4)OCI_ATTR_SERVER, errhp);
OCIHandleAlloc((dvoid*)envhp, (dvoid**)&usrhp, (ub4)OCI_HTYPE_SESSION,
(size_t)0, (dvoid**)0);
OCIAttrSet((dvoid*)usrhp, (ub4)OCI_HTYPE_SESSION, (dvoid*)username,
(ub4)strlen(username), (ub4)OCI_ATTR_USERNAME, errhp);
OCIAttrSet((dvoid*)usrhp, (ub4)OCI_HTYPE_SESSION, (dvoid*)password,
(ub4)strlen(password), (ub4)OCI_ATTR_PASSWORD, errhp);
OCISessionBegin(svchp, errhp, usrhp, OCI_CRED_RDBMS,
OCI_DEFAULT);
But I want to change it in a way that I can use tnsnames.ora.

Do not pass the dblink parameter in your program, pass an empty string over there and if you are on a UNIX/LINUX set TWO_TASK to the tns alias, in your case if dblink was a valid tnx alias set TWO_TASK to dblink and run the program

Similar Messages

  • How to use ODBC SQLDriverConnect() without using tnsnames.ora file

    I have an ODBC application that connects to an Oracle 10g database. Currently, my SQLDriverConnect() function call uses the following connection string:
    DRIVER={Oracle in OraClient10g_home1}; DBQ=MyDB.world; DBA=W; UID=foo; PWD=bar
    This requires an entry in the tnsnames.ora file that looks like this:
    MyDB.world =
    (DESCRIPTION = (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL = TCP)(Host = server1.intel.com)(Port = 1521)
    (ADDRESS =
    (PROTOCOL = TCP)(Host = server2.intel.com)(Port = 1521)
    (ADDRESS =
    (PROTOCOL = TCP)(Host = server3.intel.com)(Port = 1521)
    (ADDRESS =
    (PROTOCOL = TCP)(Host = server4.intel.com)(Port = 1521)
    (LOAD_BALANCE = yes)
    (CONNECT_DATA = (SERVER = DEDICATED)
    (SERVICE_NAME = MY_SRVC))
    However, I would really like to be able to connect using ODBC without having to create that entry in the tnsnames.ora file. I have tried to substitute the DBQ=MyDB.world with the entire (DESCRIPTION=..... string from the original tnsnames.ora file, but it returns the error:
    ORA-12154: TNS: Could not resolve the connect identifier specified.
    I have heard others are able to use sqlplus with no tnsnames.ora file and the do specify the entire (DESCRIPTION=.... string on the sqlplus connection string, but is this possible to do using the ODBC SQLDriverConnect() function? If so, do I need to use a different keyword/value pair other than DBQ=?
    Any help on this would be greatly appreciated.
    Thank you.

    How would that work in a load balanced configuration? Take a closer look at the tnsnames.ora example I included in my original post. I have 4 ADDRESS= sections to denote 4 servers that are part of the load balanced environment.
    Also, I'm not familiar with that syntax, I need to use the syntax supported by the SQLDriverConnect() API function, which looks like this:
    DRIVER={Oracle in OraClient10g_home1}; DBQ=MyDB.world; DBA=W; UID=foo; PWD=bar
    I don't know as SQLDriverConnect() would accept an alternative syntax. But the more important issue here is the ability to specify those 4 servers in the load balanced configuration as indicated by that tnsnames.ora entry.

  • Does ODBC SQLDriverConnect allow connections without using tnsnames.ora?

    I am trying to find out if the Oracle ODBC driver supports a connection attempt through the SQLDriverConnect() ODBC API function without the need to use the tnsnames.ora file. In other words, I would like to pass into the SQLDriverConnect() function the connection string information that would normally be found in the tnsnames.ora file. The purpose of this would be to force the ODBC driver to bypass reading the tnsnames.ora file entirely and simply use the connection information I pass into the connection buffer in the SQLDriverConnect() function.
    If this is possible, can someone explain how to do it? I've tried what I think should have worked, so I'm either not doing this right or this functionallity is not supported by the driver.
    Thank you.
    -Dave

    You might try logging a support request to see if that functionality got restored at some point. My recollection is a year or two old...
    The Easy Connect syntax is just another feature of the TNS layer, so it should be available to any apps using the 10g client.
    The documentation discusses using the Easy Connect Naming Method in some detail. I've not used it with the Oracle ODBC driver, but it should just work.
    Justin

  • Using tnsnames.ora file instead of oracle names server

    hi,
    sqlnet.ora file contains
    NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES)
    NAMES.DEFAULT_DOMAIN = (domain name)
    SQLNET.EXPIRE_TIME = 2
    DEFAULT_SDU_SIZE = 8761
    NAMES.PREFERRED_SERVERS =
    (ADDRESS_LIST =
    (ADDRESS =
    (COMMUNITY = TCP.world)
    (PROTOCOL = TCP)
    (Host = oranamesrvr0. domain name)
    (Port = 1575)
    NAME.PREFERRED_SERVERS =
    (ADDRESS_LIST =
    (ADDRESS =
    (COMMUNITY = TCP.world)
    (PROTOCOL = TCP)
    (Host = oranamesrvr0.domain name)
    (Port = 1575)
    There is also a tnsnames.ora file in the same path as this sqlnet.ora. Can someone tell how can i make the application use the tnsnames.ora file instead of using oracle name servers??
    Thanks in advance!!!

    917229 wrote:
    hi,
    sqlnet.ora file contains
    NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES)
    NAMES.DEFAULT_DOMAIN = (domain name)
    SQLNET.EXPIRE_TIME = 2
    DEFAULT_SDU_SIZE = 8761
    NAMES.PREFERRED_SERVERS =
    (ADDRESS_LIST =
    (ADDRESS =
    (COMMUNITY = TCP.world)
    (PROTOCOL = TCP)
    (Host = oranamesrvr0. domain name)
    (Port = 1575)
    NAME.PREFERRED_SERVERS =
    (ADDRESS_LIST =
    (ADDRESS =
    (COMMUNITY = TCP.world)
    (PROTOCOL = TCP)
    (Host = oranamesrvr0.domain name)
    (Port = 1575)
    There is also a tnsnames.ora file in the same path as this sqlnet.ora. Can someone tell how can i make the application use the tnsnames.ora file instead of using oracle name servers??
    Thanks in advance!!!In addition to SB's comment, keep in mind that the client only sees sqlnet.ora and tnsnames.ora that exist on the client machine .. or indicated by TNS_ADMIN as defined on the client machine. Setting this on the db server is meaningless to the client unless the client also resides on the db server.

  • Must PMON use tnsnames.ora to locate none-defualt listener?

    Hi,
    I just want to confirm this because it is said tnsnames.ora only used for client. So I am a little confused by this usage.
    Please give some explanation about this.
    Thanks in advance.
    Br
    Martin

    tqma wrote:
    Hi,
    I notice this, "Clients and database servers (that are clients of other database servers) use the net service name when making a connection with an application."
    The statement also tells me that tnsnames.ora only is used for client role.
    Ok, my question comes from these operations;
    1. I modify the listener.ora, adding a new none-default listener, such as on port 1899.
    2. When I want to register an instance to this new listener by statements of "alter system set local_listener=...; alter system register;", it fails.
    More details, for example, I add these codes in listener.ora
    TXT_LIS=
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = fztxt)(PORT = 1525))
    Then I issue command "alter system set local_listener=txt_lis;". This command will fail.
    I need to add this in tnsnames.ora; "Txt_lis=(ADDRESS = (PROTOCOL = TCP)(HOST = fztxt)(PORT = 1525))";
    After adding the entry in tnsnames.ora, the problem is solved. When I google this, it's said PMON needs tnsnames.ora to do name resolution.
    I think PMON is a server process. So I ask if tnsnames.ora is necessary for server side in this circumstance.Since it is contacting the listener, it is acting in client role at that point.
    OK, maybe that's splitting a hair a bit to fine ...
    I'd say OK, there is one single, not often used, time when a server process uses tnsnames. But 99.999999% of the time, when people are trying to debug connection problems and can't keep straight in their mind the difference - in location and function - between client and server processes . . . it's true enough to tell them the tnsnames is used only by client processes.
    >
    Br Martin
    Edited by: tqma on May 25, 2011 10:10 AM
    Edited by: tqma on May 25, 2011 10:13 AM

  • Connecting to Oracle database in Java using TNSNAMES.ora

    I have a program that can connect to both MSSQL and Oracle databases. It works fine when a user has defined an odbc connection, however if the user only has a tnsnames.ora, I don't know how to code the program in Java to connect to the database. I can't hard-code the server name because I don't know the database up front - I need to be able to read tnsnames.ora to get the information instead. How can I get this information? So far, the object OracleDataSource seems to be getting me the closest, however I am still failing to connect.

    In 10.2, JDBC-Thin supports TNSNAMES entries lookup in tnsnames.ora, resulting in a much simplified and driver type independent Oracle Net descriptor. You must set the system property oracle.net.tns_admin to the directory that contains your tnsnames.ora file.
    See the Oracle JDBC 10.2 doc.
    Here is a code fragment from my book (see my blog below)
    java -Doracle.net.tns_admin=$ORACLE_HOME/network/admin
    or:
    System.setProperty("oracle.net.tns_admin", "c:\oracle\net\admin");
    OracleDataSource ods = new OracleDataSource();
    ods.setTNSEntryName("tns_alias");
    ods.setUser("scott");
    ods.setPassword("tiger");
    ods.setDriverType("thin");
    Connection conn = ods.getConnection();
    Kuassi - blog http://db360.blogspot.com/

  • Linked Servers - Sql server 2005 to connect to Oracle 11g using ldap.ora instead of tnsnames.ora

    We have a SQL Server 2005 64bit box that needs a linked server created to Oracle 11g 64bit box. I have all the Oracle client software installed and can successfully connect to the Oracle database using SQL+ on the SQL Server 2005 64bit box. When I create
    the linked server and select the OraOledb.Oracle provider, I get the TNSNames error. The Oracle server does not use tnsnames.ora it uses OLAP.ora to resolve. How do I get Linked server to stop trying to connect via TNSNames and use the OLAP.ora file instead?
    I can't find any articles for this specific issues. All Oracle examples tell you to use TNSNAMES. The Oracle server is not under my companies control so I can not force the vendor to use tnsnames instead of OLAP.

    Hi,
    Have you got a resolution?
    Thank you.

  • Parameters of tnsnames.ora

    hello. i am new in oracle 10g and i want to take advice. i see the setting parameters of tnsnames.ora on Oracle Net Manager and i set the tnsnames.ora with it.
    i developed a client application working with remote oracle 10g database on windows platforms. i developet it on VisualStudio, this application can work with both ms sql and oracle 10g. the user chooses it. when the user chooses Oracle i must create connection string and connect to the remote db.
    i can implement it with two way
    1. i want only connection name which is defined in tnsnames.ora and connect over it.
    2. i make an interface user set the simple and advanced settings of connection parameters and i can insert them into connection string.
    which way should i use. i think that it is better to set all of parameters in my application because it will be easier for user. but i think about the future versions of oracle . there may be problems on them.
    what do you advice me?
    thanks.

    Hello user "user518019":
    I'm also new in the Oracle world but I have programming since a lot of years. I would recommend to you following a simple rule:
    if your applicattion is very simple you must follow the simple way to connect to DB.
    By using a "tnsnames.ora" you only need to know a DB name to connect to it. In the other hand, if your are using non-default ports o also like this (per example, a more complicated enviroment) you would need a more detailed box to especify address, port number, service name, etc, etc...
    I suppose Oracle will continue using "tnsnames.ora" a lot of years, but this is only a impression. I hope send you some help with this.

  • Again about tnsnames.ora

    thx kmensah. but I want to use tnsnames.ora. in that document introuduce the way that I used before. but I want way of using tnsnames.ora .

    Wrong Post !!!

  • Connection to db works with ezconnect but fails with tnsnames.ora

    Hi,
    When I try to connect to remote datbase using 10g ezconnect, it works fine. But when I tried to connect to same database using tnsnames.ora, it fails:
    sqlnet.ora on client side:
    ================
    ###SQLNET.AUTHENTICATION_SERVICES= (NTS)
    NAMES.DIRECTORY_PATH=(tnsnames, onames, hostname, ezconnect)
    tnsnames.ora on client side
    =================
    MRAP =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = moody)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = MRAP.ALBILAD.COM)
    Listener On DB Server:
    ===============
    $ lsnrctl status
    LSNRCTL for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production on 04-APR-2010 16:29:16
    Copyright (c) 1991, 2007, Oracle. All rights reserved.
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=moody)(PORT=1521)))
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production
    Start Date 04-APR-2010 16:28:59
    Uptime 0 days 0 hr. 0 min. 16 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP ON
    Listener Parameter File /u01/app/oracle/product/10.2.0/network/admin/listener.ora
    Listener Log File /u01/app/oracle/product/10.2.0/network/log/listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=moody)(PORT=1521)))
    Services Summary...
    Service "mrap.albilad.com" has 1 instance(s).
    Instance "mrap", status READY, has 1 handler(s) for this service...
    Service "mrapXDB.albilad.com" has 1 instance(s).
    Instance "mrap", status READY, has 1 handler(s) for this service...
    Service "mrap_XPT.albilad.com" has 1 instance(s).
    Instance "mrap", status READY, has 1 handler(s) for this service...
    The command completed successfully
    Now, on client, when I connect with each of methods written above, following is output:
    C:\Documents and Settings\c900796>sqlplus ingrian/[email protected]:1521/mrap.albilad.com
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 4 16:57:18 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> show user;
    USER is "INGRIAN"
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64
    bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    C:\Documents and Settings\c900796>sqlplus ingrian/ingrian@mrap
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 4 16:57:25 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    ERROR:
    ORA-12154: TNS:could not resolve the connect identifier specified
    Enter user-name:
    ERROR:
    ORA-12560: TNS:protocol adapter error
    Enter user-name:
    ERROR:
    ORA-12560: TNS:protocol adapter error
    SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
    C:\Documents and Settings\c900796>
    What do you suspect could be the issue?
    Br,
    Anjum

    C:\Documents and Settings\c900796>sqlplus ingrian/ingrian@mrap
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 4 16:57:25 2010
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    ERROR:
    ORA-12154: TNS:could not resolve the connect identifier specifiedstates, in no uncertain terms, that the system can not find the @mrap in the TNS translation methods. Usually that indicates a problem in finding the correct entry in the correct tnsnames.ora file. Some related thoughts:
    1) The LIST of methods allowed is found in SQLNET.ORA on the client. If multiple methods are in the list, the client will step through the methods.
    It is possible that you do not have method calling the TNSNAMES.ORA file in the list. (You appear to have that.)
    2) The mrap must be one of the entries on the left hand side of te equals sign of a stanza.
    MRAP = (DESCRIPTION (appears to provide that)
    3) The SQLNET.ORA could provide a 'default domain' to append on the end of the lookup value in TNSNAMES.ORA
    Not sure whether your post of the sqlnet.ora selectred only a few lines or the entire file.
    4) Variable issues can exist.
    - The TNS_ADMIN variable may be used to force the use of a specific directory instead of %ORACLE_HOME%\network\admin .
    - ORACLE_HOME can be adjusted by a variety of methods, and may be in both teh registry and the system environment

  • TNSNAMES.ora et HOSTS file on windows

    Hi,
    in TNSNAMES.ora for host field I put correct IP adresse.
    In hosts file of Windows I have defined an alias for the same host with wrong IP adresse. Then I can not connect to DB and I have TNS-12541 error.
    Then I put the correct adresse for host alias in hosts file. Everything is OK and I can connect to DB
    Is -it normal ? Why does not ORACLE use TNSNAMES.ora and it looks in hosts file ?
    Do you have any explanation ?
    Many thanks.

    check address in listener.ora and tnsnames.ora
    Try to connect with ip address.
    host file is used for address resolving.
    Regards

  • Is telnet use local tnsnames.ora?

    I was suprise that when the local tnsnames.ora of client was not correct,sqlplus at telnet can't connect to server,and when the file was modify,I can use sqlplus connect to oracle through telnet.
    is telnet use local tnsnames.ora?

    This is simply impossible.

  • TNS_ADMIN (path to tnsnames.ora) using Instant Client IGNORED

    Hi,
    I developed a simple utility which uses OCCI LIB from 10g release. I'm deploying it with Oracle Instant Client lite libraries.
    Everything works fine when tnsnames.ora is present in the same dir. When I move it somewhere else and set TNS_ADMIN to that directory, it doesn't work anymore:
    C:\uplob>set TNS_ADMIN=c:\tns;
    C:\uplob>echo %tns_admin%
    c:\tns;
    C:\uplob>uplob u/p@xe 15 input.dat
    Exception:12154 ORA-12154: TNS:could not resolve the connect identifier specif
    ied
    This seems very simple, but I still cannot determine why TNS_ADMIN is not being taken into account.
    Thank you for any help with this issue,
    david

    I think for Windows ,
    You may have to set this in MY-COMPUTER-->Advanced-Env-Variables
    and reboot to take effect.
    rgds

  • How to define a DSN without using a tnsnames.ora on the PC client machine

    Hi,
    Client : Windows XP with Oracle9i ODBC driver
    Server : Oracle 10 on Solaris
    I need to define a DSN which does not rely on tnsnames.ora on the client machine.
    I tried to use a file dsn, but without success, because I don't know the parameters to use.
    I used these params in the file.dsn :
    [ODBC]
    DRIVER=Oracle9i ODBC Driver
    UID=testuser
    PWD=testpw
    SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=9999))(CONNECT_DATA=(SERVICE_NAME=testSID)))
    It does not work ....

    Hrm, interesting. It always used to be DBQ but it seems it might have changed to SERVER at some point.
    Anyway, I tried this and it worked fine for me (using 10204)
    TESTFILE.DSN
    ================
    [ODBC]
    DRIVER=Oracle in OraDb10g_home1
    server=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=gdarling-pc2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
    TEST.VBS
    ==========
    set con = createobject("adodb.connection")
    con.open "filedsn=testfile;uid=scott;pwd=tiger;"
    set rs = createobject("adodb.recordset")
    rs.open "select user from dual",con
    msgbox rs.fields(0).value
    Note also that unless you really want to create a file dsn, you could also just use a dsnless connection string and pass that directly too:
    set con = createobject("adodb.connection")
    con.open "driver={Oracle in OraDb10g_home1};uid=scott;pwd=tiger;server=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=gdarling-pc2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
    set rs = createobject("adodb.recordset")
    rs.open "select user from dual",con
    msgbox rs.fields(0).value
    Hope it helps,
    Greg

  • Can i use the default value in TNSNAMES.ora file

    Hai , i connect the Vb to oralcle using Oracle data access component , and i have read the documentation for ora file.
    Most documentation show to connect oracle with vb.net , the ora file must be modified.
    My questions is , can i directly connect to Oracle without modify the ora file ?
    Thank You

    Thank you for the reply. I will read the documentation first.
    I install the oracle 10g express edition . Hence , i have two user , the sys an the other is hd.
    How the TNSNAMES.ora known i want connect to which username ?
    Thank you

Maybe you are looking for

  • Replacement iPod with identical problem.

    I just paid good money for one of the new 80GB iPod's. As soon as iTunes had successfully loaded my 40GB+ collection onto it and indicated that it was safe to disconnect, the iPod started boot cycling, and couldn't be got out of it. I got a replaceme

  • My itunes won't launch even after reinstalling.  Looked in itunes folder and somehow lost itunes library?  HELP!

    My itunes won't launch even after reinstalling.  Looked in itunes folder and somehow lost itunes library?  HELP!

  • Dare to update a running 5.0 to 5.0.1?

    Hi Everybody, I finally made it to have a running iTunes 5.0 even though it occupies about 100 MB RAM and burning is very, very slow! Also I have changed language settings (now back to english). Would you dare to update to 5.0.1 or would I be better

  • Toshiba registration error

    Hi I'm trying to register my Tablet which was purchased in Latin america in Toshiba website (http://www.csd.toshiba.com/sup/jsp/taisreg/registrationSerial.jsp). However, after submitting all my purchase details and personal information I get a messag

  • Two vendor payment against single shipment

    Dear All I am stuck on a problem where in a single shipment doc forwarding agent is different and handling agent is different .shipment cost calculation(VI01) should be different for different forwarding agent. This is the case when they are having d