-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: TNS error with Oracle connection
PostPosted: Fri Jun 13, 2008 3:45 pm 
Newbie

Joined: Tue Dec 11, 2007 3:36 pm
Posts: 7
Hello all,

I am trying to use NHibernate version 1.2 to connect to an Oracle 10g database located on the same machine as my application. Here is the NHibernate section of my app.config:

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string">Data Source=xe;User ID=scott;Password=tiger</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.OracleDialect</property>
<property name="use_outer_join">true</property>

As you can see, I am using Oracle XE, but I have had the same problem with Oracle Enterprise, Personal, etc...

When I try to open a connection in my session (which uses the session factory which uses the values from my app.config), I get the following exception:

ORA-12154: TNS:could not resolve the connect identifier specified

with the following stack trace:

at NHibernate.Impl.SessionFactoryImpl.OpenConnection()
at NHibernate.Impl.ConnectionManager.GetConnection()
at NHibernate.Impl.BatcherImpl.Prepare(IDbCommand cmd)
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List()

After reading some other posts about related problems, I copied the Oracle.DataAccess.dll from the Oracle XE bin folder into my application bin folder. This did not solve the problem. I still get the same Oracle exception.

From a command prompt I can tnsping the XE database using "tnsping xe" and this is successful.

Any suggestions?

EDIT: I should add that I can connect to this database using a normal ADO.NET connection using the same connection string as above. This leads to a related question...I think that NHibernate's oracle driver uses the normal oracle .NET client driver which is provided by Sun, so what are the differences between using the .NET client driver directly and using NHibernate's oracle driver (which uses the .NET client driver) in terms on TNS lookups and things like that? I suspect the answer to this question may help with my problem above.

EDIT 2: I replaced the connection string XML with:
<property name="connection.connection_string">Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = MYHOSTNAME)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE));User ID=scott;Password=tiger</property>

and I get the same error:
ORA-12154: TNS:could not resolve the connect identifier specified

And again, I can "tnsping xe" successfully.


Top
 Profile  
 
 Post subject: help?
PostPosted: Fri Jun 20, 2008 3:33 am 
Newbie

Joined: Tue Dec 11, 2007 3:36 pm
Posts: 7
Nobody has encountered a similar issue or can offer any help?


Top
 Profile  
 
 Post subject: Oracle client version
PostPosted: Mon Jun 23, 2008 5:00 pm 
Newbie

Joined: Mon Jun 23, 2008 4:41 pm
Posts: 1
We had ORA-12154 also, when running a 32bit application on a 64bit OS. It was due to a bug in Oracle client 10.2.0.1, caused by the parentheses in "c:\program files (x86)\..." that result from installing on WoW64. Upgrading to 10.2.0.4 fixed this. Not sure if this helps though.


Top
 Profile  
 
 Post subject: Oracle connection problem solved?
PostPosted: Sun Dec 28, 2008 1:55 am 
Newbie

Joined: Sun Dec 28, 2008 12:35 am
Posts: 2
Hi Mike,

I just started testing NHibernate and I am having this very same connection problem.
Have you already solved it? If yes, how?

Thx,
Jan


Top
 Profile  
 
 Post subject: Oracle connection problem solved?
PostPosted: Sun Dec 28, 2008 1:56 am 
Newbie

Joined: Sun Dec 28, 2008 12:35 am
Posts: 2
Hi Mike,

I just started testing NHibernate and I am having this very same connection problem.
Have you already solved it? If yes, how?

Thx,
Jan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 3:59 pm 
Newbie

Joined: Wed Feb 11, 2009 3:55 pm
Posts: 1
Try to use (SID = XE) instead of (SERVICE_NAME = XE) in the connection_string


Top
 Profile  
 
 Post subject: Re: TNS error with Oracle connection
PostPosted: Wed Nov 25, 2009 6:23 pm 
Newbie

Joined: Wed Nov 25, 2009 6:07 pm
Posts: 1
Hi all,

Definitely this message
Oracle.DataAccess.Client.OracleException: ORA-12154: TNS:could not resolve the connect identifier specified

suggests that something is wrong with the connection string. Until I found this post I didn't had any idea how to fix it.
In my case the problem was that I used a connection string like this:

<property name="connection.connection_string">Data Source=MYHOSTNAME/1521/XE;User ID=scott;Password=tiger</property>

It works using the Microsoft's Oracle provider or OLE DB but not in NHibernate, so when I change it to:

<property name="connection.connection_string">Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = MYHOSTNAME)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)));User ID=scott;Password=tiger</property>

It started working (the only thing that was missing from one of old message was ... you guess it a ")" at the end of DESCRIPTION !!!

Many Thanks!!!

Cornel2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.