Solved

NHibernate: "cannot open connection"

Posted on 2010-09-01
5
1,127 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
tikusbalap earned 500 total points
ID: 33583059
Maybe it was something wrong in your hql or .hbm config.

Try change to simple query to test:

IQuery query = session.CreateQuery("from DeviceIDRecord");
IList<DeviceIDRecord> evtList = query.List<DeviceIDRecord>();

Is there any result?
0
 

Author Comment

by:newbieweb
ID: 33583134
No, same error.  It's a connection problem.

0
 
LVL 6

Expert Comment

by:tikusbalap
ID: 33583433
What database are you using? And let me see your connection string as well.
0
 

Author Comment

by:newbieweb
ID: 33586995
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?
0
 

Author Closing Comment

by:newbieweb
ID: 33601848
Thanks.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question