Solved

NHibernate: "cannot open connection"

Posted on 2010-09-01
5
1,062 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSL https .net web site force redirect 3 36
SQL Login 17 40
Advice on Xojo as a development tool over VB. 4 39
How to add <appSettings> to the webconfig file 2 21
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now