views:

249

answers:

1

I'm trying to save text fields in MySql using NHibernate in Asp.Net frame work. But while executing this I got the error"Object reference not set to an instance of an object". If anyone knew help me...

Here is the code.

if (!Page.IsPostBack) 
{
   IList siteList; 
   ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory(); 
   using (ISession session = factory.OpenSession()) 
   {
      ICriteria sc = session.CreateCriteria(typeof(Employee )); 
      siteList = sc.List(); 
      session.Close(); 
   } 
   factory.Close(); 
}
+1  A: 

*Can you post a stack trace? And a description of how you are configuring *

If i had to take a guess the crash is in (because of missing/incorrect configuration information):

new NHibernate.Cfg.Configuration().Configure().Build().SessionFactory()

Nix
<?xml version="1.0" encoding="utf-8" ?><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"><session-factory><property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property><property name="connection.connection_string">Server=localhost;Database=hrms;User ID=root;Password=siva;CharSet=latin1</property> <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property> <mapping assembly="WebApplication1" /> </session-factory></hibernate-configuration>
Siva
<?xml version="1.0" encoding="utf-8" ?><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"><session-factory><property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property><property name="connection.connection_string">Server=localhost;Database=hrms;User ID=root;Password=siva;CharSet=latin1</property><property name="dialect">NHibernate.Dialect.MySQL5Dialect</property><mapping assembly="WebApplication1" /> </session-factory></hibernate-configuration>
Siva