Link to home
Start Free TrialLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

NHibernate: "cannot open connection"

On the line of code below which says FAILS HERE I get an exception.

"cannot open connection"

I assume I have a configuration problem with the hibernate.cfg.xml file but can not find the problem since the exception is being thrown by NHibernate. Any idea where to look?



  at NHibernate.Impl.SessionFactoryImpl.OpenConnection()
   at NHibernate.Impl.ConnectionManager.Connect()
   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[T](String query, QueryParameters parameters)
   at NHibernate.Impl.QueryImpl.List[T]()
   at PizzaPilot.Server.Runtime.Impl.ServerObjectStoreImpl.GetAllDeviceRecords() in C:\Documents and Settings\Administrator\Desktop\Code\PPServer\releases\DDServer_AmericanaPhase1\PizzaPilotRuntime\PizzaPilot\Server\Runtime\Impl\ServerObjectStoreImpl.cs:line 328
   at MobileService.InitializeComponent() in c:\Documents and Settings\Administrator\Desktop\Code\PPServer\releases\DDServer_AmericanaPhase1\CentralizedMobileService\App_Code\MobileService.cs:line 43
public IList<DeviceIDRecord> GetAllDeviceRecords()
        {
            ISessionFactory factory = nhibConfig.BuildSessionFactory();
            ISession session = factory.OpenSession();

            String q = "from DeviceIDRecord as rec where rec.UID is not null";
            IQuery query = session.CreateQuery(q);
            IList<DeviceIDRecord> evtList = query.List<DeviceIDRecord>();  <<<<<< FAILS HERE

            return evtList;
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tikusbalap
tikusbalap
Flag of Indonesia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of curiouswebster

ASKER

No, same error.  It's a connection problem.

What database are you using? And let me see your connection string as well.
I am using SQL Express 2005.

    <property name="connection.connection_string">Server=localhost\SQLEXPRESS;initial catalog=PPDB01;User Id=sa;Password=sqlserversapassword;</property>


Is there a way to verify this connection string is actually being use by NHibernate?
Thanks.