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: