Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NHibernate: "cannot open connection"

Posted on 2010-09-01
5
Medium Priority
?
1,192 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
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
tikusbalap earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 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