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.
|