VijayMathew
VijayMathew

Reputation: 55

Nhibernate isession.save method throws generic exception error

I am new to Nhibernate. In my application i get the following exception

 NHibernate.Exceptions.GenericADOException: could not insert: [PAIRAlertAdmin.VO.TriggerLogVO][SQL: INSERT INTO triggerlog (TriggeredUserID, TriggeredDate, TriggeredMode, TriggeredIP, TriggerDescription) VALUES (?, ?, ?, ?, ?)] ---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution.

The following is the code that generates this error

    public void triggerLog(String logDetail, String AlertMode)
    {
        TriggerLogVO triggerLogVO = new TriggerLogVO();
        triggerLogVO.TriggeredUserID = Convert.ToInt32(Session["userid"]);
        triggerLogVO.TriggeredMode = AlertMode;
        triggerLogVO.TriggeredDate = System.DateTime.Now.ToString();
        triggerLogVO.TriggeredIP = BAL.PublicVariablesBAL.RemoteIPAddress;
        triggerLogVO.TriggerDescription = logDetail.ToString(); ;
        iSession.Save(triggerLogVO);
        iSession.Flush();
    }

The above function generates the error while saving log information. This function will be called after long time (say for example 6 to 8 hrs) because that much business rules are checked and executed finally this method called and writing the log information in mysql database table.

On the row where I calll iSession.Save it throws the exception.

any help will be appreciated.

Following is my mapping file :

<id name="TriggerID" column="ID" type="Int32">
  <generator class="native"></generator>
</id>

<property name="TriggeredUserID" column="TriggeredUserID" type="Int32"></property>
<property name="TriggeredDate" column="TriggeredDate" type="string"></property>
<property name="TriggeredMode" column="TriggeredMode" type="string"></property>
<property name="TriggeredIP" column="TriggeredIP" type="string"></property>
<property name="TriggerDescription" column="TriggerDescription" type="string"></property>

Thanks inadvance

Upvotes: 0

Views: 556

Answers (1)

Mharlin
Mharlin

Reputation: 1705

When you get a GenericADOException it means that the database could not execute the sql that was supplie to it. I use Nhibernate Profiler to debug things like that. It will show you the sql that it tried to execute. If you run the same sql code against your db you usually get a more detailed exception message.

Upvotes: 1

Related Questions