-->
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.  [ 5 posts ] 
Author Message
 Post subject: "ERROR [08004] unavailable database"
PostPosted: Thu Jan 26, 2006 10:18 am 
Newbie

Joined: Thu Jan 26, 2006 9:06 am
Posts: 2
Hi

I've just started looking at NHibernate, and I'm having a problem connecting to my database from a web service. I've been struggling all day with this problem and I'm getting pretty frustrated.

My code is quite simple. Here's my web method:

Code:
[WebMethod]
public bool SaveEvent(string message)
{
  Configuration nHibCfg = new Configuration();
  nHibCfg.AddFile(Context.Server.MapPath("") + @"\Event.hbm.xml");
  ISessionFactory nHibSessFactory = nHibCfg.BuildSessionFactory();
  ISession nHibSess = nHibSessFactory.OpenSession();
  ITransaction nHibTrans = nHibSess.BeginTransaction();

  Event ev = CreateEvent();
  ev.Data = message + ", event created in WebService.";

  nHibSess.Save(ev);
  nHibTrans.Commit();
  nHibSess.Close();
  return true;
}


An NHibernate.ADOException is thrown when I call BeginTransaction(), with the error message "cannot open connection". It's InnerException (also an NHibernate.ADOException) says "Could not create connection from Driver", and this exception's InnerException (a System.Data.Odbc.OdbcException) says "ERROR [08004] unavailable database". The nHibSessFactory.ConnectionProvider does have the correct connectionstring however.
For stacktraces, see below.

I have pretty much the exact same code and setup in a console application, and it works fine. I believe the only differences are
    - The class to persist is called TestEvent
    - The mapping file reflects the different namespace and class name:
      <class name="Tester.TestEvent, Tester" table="events">
    - Obviously no need for the Context.Server.MapPath() call.
    - Config settings are of course in app.config
The fact that essentially the same code and setup works in a console app, makes me wonder if it could be a security problem?

Below are my details as requested by the forum template. I hope I remembered everything :)

Hope someone can help me out here, as this is getting quite frustrating.

Regards,
NorCan



Hibernate version:
1.0.2.0

Configuration settings:
In Web.config:
Code:
<configSections>
  <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System,
      Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
   
  <nhibernate>
    <add key="hibernate.connection.provider"
         value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="hibernate.dialect"
         value="NHibernate.Dialect.FirebirdDialect" />
    <add key="hibernate.connection.driver_class"
         value="NHibernate.Driver.OdbcDriver" />
    <add key="hibernate.connection.connection_string"
         value="DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=somepassword;DBNAME=MTBS1604M.GDB" />
  </nhibernate>

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="EventSaverService.Event, EventSaverService" table="events">
    <id name="MediaType" column="Media_Type" type="int">
      <generator class="assigned" />
    </id>
    <property name="SerialNr"   column="Serial_Nr" type="int"/>
    <property name="UserNr" column="User_Nr" type="int"/>
    <property name="SessionNr" column="Session_Nr" type="int"/>
    <property name="TransNr" column="Trans_Nr" type="int"/>
    <property name="TrSeqNr" column="Tr_Seq_Nr" type="int"/>
    <property name="OpMode" column="Op_Mode" type="int"/>
    <property name="Date" column="Event_Date" type="DateTime"/>
    <property name="Time" column="Event_Time" type="DateTime"/>
    <property name="DateAndTime" column="Event_DateTime" type="DateTime"/>
    <property name="Category" column="Event_Cat" type="int"/>
    <property name="Nr" column="Event_Nr" type="int"/>
    <property name="Para" column="Event_Para" type="int"/>
    <property name="Para2" column="Event_Para2" type="int"/>
    <property name="Data" column="Evant_Data" type="String" length="50"/>
    <property name="Urgency" column="Urgency" type="int"/>
    <property name="ExStatus" column="Ex_Status" type="int"/>
   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
See above

Full stack trace of any exception that occurs:
NHibernate.ADOException: "cannot open connection"
StackTrace: "at NHibernate.Impl.SessionFactoryImpl.OpenConnection()\r\n at NHibernate.Impl.SessionImpl.Connect()\r\n at NHibernate.Impl.SessionImpl.get_Connection()\r\n at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel)\r\n at NHibernate.Transaction.TransactionFactory.BeginTransaction(ISessionImplementor session, IsolationLevel isolationLevel)\r\n at NHibernate.Transaction.TransactionFactory.BeginTransaction(ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.BeginTransaction()\r\n at EventSaverService.EventSaver.SaveEvent(String message) in c:\\inetpub\\wwwroot\\eventsaver\\eventsaver.asmx.cs:line 73"

InnerException:
NHibernate.ADOException: "Could not create connection from Driver"
StackTrace: "at NHibernate.Connection.DriverConnectionProvider.GetConnection()\r\n at NHibernate.Impl.SessionFactoryImpl.OpenConnection()"

InnerException:
System.Data.Odbc.OdbcException: "ERROR [08004] unavailable database"
StackTrace: "at System.Data.Odbc.OdbcConnection.Open()\r\n at NHibernate.Connection.DriverConnectionProvider.GetConnection()"

Name and version of the database you are using:
Firebird 1.5

Debug level Hibernate log excerpt:
Haven't been able to configure log4net properly yet.
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 12:46 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Looks like NH can't find your configuration. You say you are configuring it from app.config, but web applications are supposed to be configured from web.config.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:40 am 
Newbie

Joined: Thu Jan 26, 2006 9:06 am
Posts: 2
sergey wrote:
Looks like NH can't find your configuration. You say you are configuring it from app.config, but web applications are supposed to be configured from web.config.


Hi

I know it reads my configuration, because when I debug I can see that it has picked up the correct connection string, so that's not it. When I mentioned app.config it was as one of the differences in the console application where NHibernate worked.

Regards,
NorCan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:50 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Well, another difference is that, by default, aspnet is running under another user account (which has much less privileges). You should make sure that the ODBC is configured correctly for that user.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:52 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Sorry, I'm being stupid again :) I re-read your message, and now it looks to me that this is not a problem of NHibernate. Doing a Google search on the error message, the first page it returned was this:

http://www.experts-exchange.com/Web/Q_21499645.html

Please try it and tell me if it helps.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.